Page 1 of 1 1
Topic Options
#14544 - 2001-11-23 10:02 AM Arrays & Readprofilestring
t_pickering Offline
Fresh Scripter

Registered: 2001-11-23
Posts: 26
I would like to be able to read some data from a configuration file and put it in to an array.

So far i've got :-

code:

$i = 0

DIM $groupname[3]
DIM $driveletter[3]
DIM $sharepath[3]

do

$groupname[$i] = readprofilestring("c:\config.ini","map_drives","$groupname[$i]")
$driveletter[$i] = readprofilestring("c:\config.ini","map_drives","$driveletter[$i]")
$sharepath[$i] = readprofilestring("c:\config.ini","map_drives","$sharepath[$i]")

if $groupname[$i] = "" or ingroup($groupname[$i])
use $driveletter[$i] $sharepath[$i]
if @error = 0
? "Connected " + $driveletter[$i] + " to " + $sharepath[$i]
else
? "Error connecting " + $driveletter[$i] + " to " + $sharepath[$i]
endif
$i = $i + 1
else
$i = $i + 1
endif

until $i = 3


The config file is formatted like:-

code:

[map_drives]

$groupname[0] = ""
$driveletter[0] = "x:"
$sharepath[0] = "\\something\something"

$groupname[1] = ""
$driveletter[1] = "y:"
$sharepath[1] = "\\something\something"

$groupname[2] = ""
$driveletter[2] = "t:"
$sharepath[2] = "\\something\something"


The problem is I would like the script to work out the number of objects in the array and also the

code:
until $i =

.
So my questions is, is there a way of counting/reading the number of lines in a section of a config file?

Top
#14545 - 2001-11-23 11:29 AM Re: Arrays & Readprofilestring
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
Got it:
For example, you have this format in you ini file :
code:

[ShareDrives]
01="\\ServerB\"+$CurrentGroup
03=@HOMESHR
04="\\ServerG\"+$custv_group
05=Erd Drive (only to remember)


a readprofilestring("ini file", "ShareDrive","") will report this:
01 03 04 05
So you can after do a split on it
Here's my udf from my PAMLS script (not fully working)
Beware, it was for Kix4 RC1, so you may have to change the redim and ubound max values used

code:

;Function ReadProfileGroup()
;
;Author: Heitz Alex (HeitzAlexandre@wanadoo.fr) a.k.a Popov Kapov
;
;Action: Read all the values from all keys in the specified section of an
; initialization file
;
;Syntax: ReadProfileGroup("File Name", "Section")
;
;Parameters: File Name (Required)
; 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 (Required)
; A string that specifies the section to read. If empty, the
; function will return nothing
;
;Remarks: Same as kixtart ReadprofileString command.
;
;Returns: Array containing only key value, readed from first to last.
;
Function ReadProfileGroup($F_inifile, $F_Inigroup)
Dim $F_Element
for each $F_Element in split(Readprofilestring($F_inifile, $F_Inigroup,""),chr(10))
$f_element=ltrim(rtrim($f_element))
If len($f_element)
redim preserve $ReadProfileGroup[ubound($ReadProfileGroup)+1]
$ReadProfileGroup[ubound($ReadProfileGroup)-1]=readprofilestring($F_inifile, $F_Inigroup, $f_element)
endif
next
if not len($ReadProfileGroup[ubound($ReadProfileGroup)]) >0
redim preserve $ReadProfileGroup[ubound($ReadProfileGroup)]
endif
endfunction

I will post it in the UDF library when i'll get the time to debug it

[ 23 November 2001: Message edited by: Popovk ]

_________________________
? getobject(Kixtart.org.Signature)

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.054 seconds in which 0.03 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