Valid on UNIX and Windows platforms
The ReadIniSection function retrieves an entire section from an initialization (.ini) file.
Function format:
ReadIniSection( section as String, result as String, filename as String) as Integer
Identifies the section to be retrieved.
Identifies the string variable that is to receive the section.
Identifies the name of the initialization (.ini) file. If only the file name is specified in a Windows environment, the Windows directory is searched, while in non-Windows environments, the current directory is searched.
ReadIniEntry() and ReadIniSection() return a positive value if the call succeeds; otherwise, they return zero (0). The function searches the initialization file for a section that matches the name specified by section and then copies all the entries to the result variable in the following format:
Entry_1 = Value_1 <LF> Entry_n = Value_n <LF>
Example:
Function strTok(in As string, BYREF pos As Integer, token As String, BYREF out As String) As Boolean
Dim buf As String
Dim len As Integer
If (pos > Len(in)) Then
strTok = FALSE
Else
buf = Mid(in, pos)
len = Instr(buf, token)
If len = 0 Then
out = buf
pos = pos + Len(buf) + 1
Else
out = Mid(buf, 0, len-1)
pos = pos + len + 1
End If
strTok = TRUE
End If
End Function
Dim attrList, str, lf As string
Dim pos As Integer
' clear screen
ClrScr()
If Not(ReadIniSection("LIST", attrList, "c:\temp\test.ini")) Then
MessageBox("Can not read LIST section", "DMS", MB_OK + MB_ICONEXCLAMATION)
SetStatus(1)
Exit
End If
Print("[LIST]")
pos = 0
lf = chr(10)
While (strTok(attrList, pos, lf, str))
Print(str)
Wend
If Not(ReadIniEntry("SINGLE", "Entry", attrList, "c:\temp\test.ini")) Then
MessageBox("Can not read SINGLE section", "DMS", MB_OK + MB_ICONEXCLAMATION)
SetStatus(2)
Exit
End If
Print("[SINGLE]" + NEWLINE$ + "Entry=" + attrList)
If Not(DeleteIniEntry("SINGLE", "Entry", "c:\temp\test.ini")) Then
MessageBox("Can not delete [SINGLE].Entry ", "DMS", MB_OK + MB_ICONEXCLAMATION)
SetStatus(3)
Exit
End If
If Not(DeleteIniSection("LIST", "c:\temp\test.ini")) Then
MessageBox("Can not delete LIST section", "DMS", MB_OK + MB_ICONEXCLAMATION)
SetStatus(4)
Exit
End If
|
Copyright © 2014 CA Technologies.
All rights reserved.
|
|