#25318 - 2002-07-18 03:04 AM
Help.... Problems with a function (which is using ReadProfileString)
|
t_pickering
Fresh Scripter
Registered: 2001-11-23
Posts: 26
|
Hi Guys,
The function below reads in each section and it's data from a config file into an array. The array is then rename to the section name. This works ok when each section has data, but as soon as one of the sections doesn't have any data it screws up. The script reads in the data from the next section into an incorrectly named array.
Any idea on how to fix the problem?
code:
FUNCTION ReadProfileSectionData()
DO IF INSTR($line, "[") = 1 $pos_start = INSTR($line, "[") + 1 $pos_finish = INSTR($line, "]") - 2 $section_name = SUBSTR($line, $pos_start, $pos_finish) $section_name = LCASE($section_name) GLOBAL $section_data[0] $i = 0 DO $line = READLINE(1) SELECT CASE $line = ""
CASE INSTR($line, ";") = 1
CASE INSTR($line, "[") = 1
CASE 1 REDIM PRESERVE $section_data[$i] $section_data[$i] = $line $i = $i + 1 ENDSELECT UNTIL INSTR($line, "[") = 1 $result = EXECUTE("$$$section_name = $section_data") ELSE $line = READLINE(1) ENDIF UNTIL $line = "[END]"
ENDFUNCTION
code:
config.ini
[TESTLAB] subnet=192.168.99
[EXCLUDED_HOSTS] hostname=12345 hostname=12345 hostname=12345 hostname=12345 hostname=12345 hostname=12345 hostname=12345 hostname=12345
[SHARES] share0_groupname=domain admins share0_driveletter=S share0_path=\\eee\installs$ share1_groupname=staff share1_driveletter=W share1_path=\\eee\temp share2_groupname= share2_driveletter=X share2_path=\\eee\data [END]
(MCA: complete subject) [ 18 July 2002, 08:43: Message edited by: MCA ]
|
|
Top
|
|
|
|
#25320 - 2002-07-18 04:32 AM
Re: Help.... Problems with a function (which is using ReadProfileString)
|
t_pickering
Fresh Scripter
Registered: 2001-11-23
Posts: 26
|
Hi,
That does't work. It only reads in the data before the equals signs.
Tim. [ 18 July 2002, 04:42: Message edited by: t_pickering ]
|
|
Top
|
|
|
|
#25321 - 2002-07-18 05:54 AM
Re: Help.... Problems with a function (which is using ReadProfileString)
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Tim,
Why doesn't READPROFILESTRING work?
Think of it this way... Read in an INI File, by section, by key and what the key's data means.
So, if we take from the documentation the following:
READPROFILESTRING Action Retrieves a string from an initialization file.
Syntax READPROFILESTRING ("file name", "section", "key")
Parameters
File name A string that names the initialization file. If this parameter does not include a full path, Windows searches for the file in the Windows directory.
Section A string that specifies the section containing the key name. If this parameter is empty, READPROFILESTRING returns all section names in the file.
Key A string containing the key name whose associated string is to be retrieved. If this parameter is empty, all key names in the section specified by section are returned.
Remarks This function is provided for compatibility with 16-bit Windows – based applications. Win32 – based applications store initialization information in the registry.
Returns 0 Function returns a string representing the value of the specified key
Example $dev = ReadProfileString("win.ini", "Windows", "Device")
HTH,
Kent
|
|
Top
|
|
|
|
#25322 - 2002-07-18 08:42 AM
Re: Help.... Problems with a function (which is using ReadProfileString)
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
Te concept of such files is that the keys are the same. In your example we read many times hostname=12345 Two suggestion: - read the unchanged file with Open/RedaLine/Close - change hostname=12345 to f.e. hostname1=12345 hostname2=12345 hostname3=12345 for make it possible to use the ReadProfileString function. greetings.
|
|
Top
|
|
|
|
#25324 - 2002-07-21 11:38 AM
Re: Help.... Problems with a function (which is using ReadProfileString)
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1636 anonymous users online.
|
|
|