Page 1 of 1 1
Topic Options
#48330 - 1999-10-09 12:45 AM readprofilestring returns key names instead of values with empty key field
Anonymous
Unregistered


I am trying to read all values of keys from a section in an ini file into an array by leaving the key section blank (""). The documenation states that kixtart will return all key names in a section if the key name is left out. What good is this for? I don't want the key names, I need the values returned. Any ideas? Was this design intentional, or am I missing something here?
Top
#48331 - 1999-10-14 10:10 AM Re: readprofilestring returns key names instead of values with empty key field
Anonymous
Unregistered


The design was intentional. The point of it is: If you know what section and keyname you want, you can specify it.

READPROFILESTRING ("file name", "section", "key")

If you do not know what section, or what key you specify "" and you get a list of all of them in the file. This would be used if for instance you had an .ini file with an undetermined number of parameters, but you needed to make sure that they were all read and set in some way. You could ask for the list of all sections, then ask for the list of all keys and churn your way through them all. I have a piece of code I swiped that does just that (I think I swiped it off this board even):
Below is an example of how to walk through all of the sections & keys in an INI file. If you have trouble with copy/paste, then send me an e-mail here:
Marty.List "at" Janus.com


$Sections = ReadProfileString("$CollectionPath\$NextFile", "", "")
If $Sections = "" Shell '%ComSpec% /C Ren "$CollectionPath\$NextFile" "*.BAD"' EndIf
While $Sections
$Sections = "$Sections" + Chr(10)
$LineFeed = InStr("$Sections", Chr(10))
$NextSection = SubStr("$Sections", 1, $LineFeed-1)
$Sections = SubStr("$Sections", $LineFeed+1, Len("$Sections")-$LineFeed)
While $NextSection
If $Verbose $Status = "Processing $NextFile [$NextSection]" GoSub "_ShowStatus" EndIf

$Keys = ReadProfileString("$CollectionPath\$NextFile", "$NextSection", "")
If $Keys = "" Shell '%ComSpec% /C Ren "$CollectionPath\$NextFile" "*.BAD"' EndIf
While $Keys
$Keys = "$Keys" + Chr(10)
$LineFeed = InStr("$Keys", Chr(10))
$NextKey = SubStr("$Keys", 1, $LineFeed-1)
$Keys = SubStr("$Keys", $LineFeed+1, Len("$Keys")-$LineFeed)

While $NextKey
If $Verbose $Status = "Processing $NextFile [$NextSection] $NextKey" GoSub "_ShowStatus" EndIf

$LoginRecord = ReadProfileString("$CollectionPath\$NextFile", "$NextSection", "$NextKey")
$ResultCode = WriteProfileString("$MasterLogFile", "$NextSection", "$NextKey", "$LoginRecord")
If $ResultCode <> 0
$Message = "WARNING: Collector.KiX failed, WriteProfileString($MasterLogFile, $NextSection, $NextKey, $LoginRecord) returned $ResultCode"
GoSub "_Notify"
GoTo "_Complete"
EndIf

$LineFeed = InStr("$Keys", Chr(10))
$NextKey = SubStr("$Keys", 1, $LineFeed-1)
$Keys = SubStr("$Keys", $LineFeed+1, Len("$Keys")-$LineFeed)
Loop
Loop

$LineFeed = InStr("$Sections", Chr(10))
$NextSection = SubStr("$Sections", 1, $LineFeed-1)
$Sections = SubStr("$Sections", $LineFeed+1, Len("$Sections")-$LineFeed)
Loop
Loop

------------------
K Torkelson
Sys Admin Analyst
ktorkelson@providentfunding.com


Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.047 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org