Properties module - useful module for working with properties / ini files

Discussion in 'Code Samples & Tips' started by Erel, Nov 7, 2008.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Almost every application needs to use some sort of configuration file to store configurable values.
    The attached Properties module, can load and save keys and values in a simple syntax.
    This library uses hashtables from agraham's collections library to store the pairs of keys and values in an efficient data structure.
    You can use this module to work with any number of properties files.
    A (very) small example is also included in the zip file.
    Code:
    Sub App_Start
        
    'Load an existing properties file:
        [B]p = Properties.Load("test.ini")[/B] 'Returns the handle to the properties table.
        ListBox1.Add("Width: " & [B]Properties.GetProperty(p,"Width")[/B])
        ListBox1.Add(
    "Height: " & [B]Properties.GetProperty(p,"Height")[/B])
        ListBox1.Add(
    "Name: " & [B]Properties.GetProperty(p,"Name")[/B])
        Form1.Show
        
        
    'Change some properties and save the file:
        [B]Properties.AddProp(p,"Width",333)
        Properties.AddProp(p,
    "Height",111)
        Properties.AddProp(p,
    "Name","New Name")
        Properties.Save(p,
    "test.ini")[/B]
    End Sub
    The file syntax is:
    Code:
    'This is a comment
    'Key=Value

    Width=
    200
    Name=Some Name
    Height=
    300
     

    Attached Files:

  2. hzimmer3

    hzimmer3 Member Licensed User

    Properties

    I find this very interesting for handling property files,
    but I wonder how I can use this in Basic4Android.
    Do I need to include the library collection, how?

    Thanks,

    Helmut
    Cologne/Germany
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    This is a Basic4ppc library. You cannot use it in Basic4android. However it is very similar to File.ReadMap / WriteMap which are available in Basic4android.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice