[Gambas-user] BUG: Settings.Keys (gb.settings)
Lewis Balentine
lewis at ...3412...
Thu Nov 27 18:22:59 CET 2014
Reference: http://gambaswiki.org/wiki/comp/gb.settings/settings/keys
Settings.Keys (gb.settings)
Property Read Keys As _Settings_Keys
Return a virtual object used for enumerating all the keys used by the
setting file.
Wrong: It returns a array of strings that are the "Slot Names".
Key Definition: A value line, which is a "Key=Value" pair.
Slot Definition: A slot line, which begins with a "[" character, and
ends with a "]" character.
Work-Around: The following function will return the key names.
'-------------
Public Function GetSettingsKeys(FileName As String) As String[]
Dim AllKeys As New String[]
Dim p As Integer
Dim OneLine, C, SlotName As String
Dim FileStream As Stream
' Well nuts! Settings.Keys returns a list of the slots rather than
the keys.
' This function returns all the key in a array of Strings in the form
' "SlotName/KeyName" as used by the Settings read and Write functions.
FileStream = Open FileName For Read
While Not Eof(FileStream)
Line Input #FileStream, OneLine
OneLine = Trim(Oneline)
If IsNull(OneLine) Then
' do nothing
Else
C = Left(OneLine, 1)
Select Case C
Case "#", ";" ' comment
' do nothing
Case "[" ' new slotname
SlotName = Mid(Left(OneLine, InStr(OneLine, "]") - 1), 2) & "/"
Case Else ' new key
p = InStr(Oneline, "=")
If P <> 0 Then AllKeys.Add(SlotName & Trim(Left(OneLine, p - 1)))
End Select
End If
Wend
Close #FileStream
Return AllKeys
End
'-------------
Example use:
Public Sub Button1_Click() ' button labeled "Test"
Dim S As String
For Each S In GetSettingsKeys(TextBox1.Text)
Print S
Next
End
'-------------
cheers,
lewis at ...3412...
More information about the User
mailing list