### Ini Files Map Format

These are examples of working with Ini like files.
The content of the ini file uses the Java map format:
Key = Value
Usage of below example
Declare public global vars
`Sub Process_Globals
Public FIniMap As Map ' Map holding the ini Keys=Values
Public FIniFile As String = "myini.ini" ' Textfile in which the inimap is stored
...
End Sub`
Init inimap and read the file content into the inimap
`Sub AppStart (Form1 As Form, Args() As String)
' Init the inimap
FIniMap.Initialize
' Read the content of the inifile and assigne content to the inimap
FIniMap = readIni(FIniFile)
...
To use the sub's to get and put ini values, examples
' Show number of entries in the inimap:
Log("Number of Ini entries = " & FIniMap.Size)
' Read Ini Key "Key9". If not found, then value "False" is assigned
Log("Ini Key9 = " & getIni(FIniMap, "Key9", "False"))
' Assign new value to Key9
putIni(FIniMap, "Key9", "True")
' Save the inimap to the inifile
saveIni(FIniMap, FIniFile)
The sub's to be included in the code direct or define as a class
' SECTION: INI
' The ini file is stored in the app folder (same as where the jar file is stored)
' Read the Ini values from the ini file into a global map
' Param IniFile: The ini file to be read
' Return: Map of ini entries (key=Value)
`Public Sub readIni(IniFile As String) As Map
Dim Map1 As Map
Map1.Initialize
' If the ini file exists, read it else create an empty file
If File.Exists(File.DirApp, IniFile) = True Then
Map1 = File.ReadMap(File.DirApp, IniFile)
Else
File.WriteMap(File.DirApp, IniFile, Map1)
End If
Return Map1
End Sub`
' Save the ini values from the map into a file
' Parameter Map: Map holding the ini entries
' Parameter IniFile: The ini file holding the entries
`Public Sub saveIni(Map1 As Map, IniFile As String)
File.WriteMap(File.DirApp, IniFile, Map1)
End Sub`
' Delete the ini file
' Parameter IniFile: The ini file to be deleted
`Public Sub deleteIni(IniFile As String)
File.Delete(File.DirApp, IniFile)
End Sub`
' Get an Ini value from the map for a given key. if not found, use default value.
' Parameter Map: Map holding the ini entries
' Parameter Key: Key to be changed or added
' Parameter Default: Default value to be assigned to the key
' Return: Ini value as String
`Public Sub getIni(Map1 As Map, Key As String, Default As String) As String
Dim s As String
s = Default
For i = 0 To Map1.Size - 1
If Map1.GetKeyAt(i) = Key Then
s = Map1.GetValueAt(i)
End If
Next
Return s
End Sub`
' Put an Ini value for a key into the map
' Parameter Map: Map holding the ini entries
' Parameter Key: Key to be changed or added
' Parameter Value: Value to be assigned to the key
`Public Sub putIni(Map1 As Map, Key As String, Value As String)
Map1.put(Key, Value)
End Sub`
' Delete an Ini value from the map for for a key
' Parameter Map: Map holding the ini entries
' Parameter Key: Key as String to delete from the map
`Public Sub delIni(Map1 As Map, Key As String)
Map1.Remove(Key)
End Sub`
`

Changed: , Category: Ini Files, File: T6C200M1468.htm, ID: 1468