Page 1 of 1 1
Topic Options
#153210 - 2005-12-09 02:27 PM ReadProfileString Used In a Loop?
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
Can I use ReadProfileSttring in a loop?

INI File is formatted as so:
[ComputerName]
User=USERNAME
IP=IPADDRESS
Mac=MACADDRESS

How would I read each computername? The file has about 65 entries formatted as the example. I've done loops with the readline command, but I'm not exactly sure how to make the readprofile string work in a similar fashion. I want to have a variable extracted that is only one computername. Then the next time I read the file, I want the next computername, and so on.....

Thanks in advance.

Top
#153211 - 2005-12-09 02:41 PM Re: ReadProfileString Used In a Loop?
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
$ = Split(ReadProfileString("Filename","",""),CHR(10))

This will give you an array with all of the "Sections" included within that array
_________________________
Today is the tomorrow you worried about yesterday.

Top
#153212 - 2005-12-09 02:42 PM Re: ReadProfileString Used In a Loop?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if you use readprofile without the extra arguments, you get back the full list of sections.
Code:

$listOfSections = readprofilestring("myIniFile.ini","","")
$splittedList = split($listOfSections,chr(10))
for each $section in $splittedList
$section ?
next

_________________________
!

download KiXnet

Top
#153213 - 2005-12-09 02:44 PM Re: ReadProfileString Used In a Loop?
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
getini() UDF
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#153214 - 2005-12-09 02:46 PM Re: ReadProfileString Used In a Loop?
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Code:

$sections = split(readprofilestring($SoftFile,'',''),chr(10))
for each $section in $sections
if $section > " "
$SoftInv = Getini($SoftFile,$section,chr(9))
for each $entry in $SoftInv
...
next
endif
next

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#153215 - 2005-12-09 02:53 PM Re: ReadProfileString Used In a Loop?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
eh, what's the usage for getini in this picture?
_________________________
!

download KiXnet

Top
#153216 - 2005-12-09 03:45 PM Re: ReadProfileString Used In a Loop?
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
You guys amaze me. I've never seen a message board with such quick responses! Thanks. I'll take a look at each suggestion!
Top
#153217 - 2005-12-09 04:41 PM Re: ReadProfileString Used In a Loop?
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
I don't quite understand the usage of the CHR command. I know it's a chracter code, but I don't see why it's in the examples.
Top
#153218 - 2005-12-09 06:20 PM Re: ReadProfileString Used In a Loop?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the list returned by readprofilestring is separated newline character.
guess, in the old days, the only use for it was to display the contents of ini and thus, chr(10) seems nice. actually, the reverse engineering of the output came around just a couple years ago on this board.

anyway, you can test this by not splitting the output and showing it in the console window directly:
Code:
readprofilestring("myIniFile.ini","","") ?

_________________________
!

download KiXnet

Top
#153219 - 2005-12-30 07:05 PM Re: ReadProfileString Used In a Loop?
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
What's wrong with this code?

Code:
  
BREAK ON
$file1 = Open(1,"activeusers.csv",5)
$inifile = "C:\Documents and Settings\Administrator.SOMEHOSP\Desktop\Admin Tools\KIX-Work\active-users.ini"
$listOfSections = readprofilestring($inifile,"","")
$splittedList = split($listOfSections,chr(10))

for each $section in $splittedList
$user=readprofilestring($inifile,$section,"user")
$os=readprofilestring($inifile,$section,"os")
$ip=readprofilestring($inifile,$section,"ip")
$date=readprofilestring($inifile,$section,"lastbootdate")
$x = Writeline(1, $section + ","+ $user + "," + $os + "," + $ip +","+ $date + @crlf)
$section + ","+ $user + "," + $os + "," + $ip +","+ $date + @crlf
;sleep 1
next




The CSV file has the first 48 or so lines correct, then it duplictes the INI file section names over again. It seems to do it as many times as I have the $section in the for..next loop.

Thanks in advance.

Top
#153220 - 2005-12-31 12:13 AM Re: ReadProfileString Used In a Loop?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep.
you got the empty thingie.
when you split the section names, the last one is empty as after each value is linefeed.
that results in readprofilestring($inifile,"","user") all over again.
change:
$splittedList = split($listOfSections,chr(10))

to:
$splittedList = split(left($listOfSections, -1),chr(10))
_________________________
!

download KiXnet

Top
#153221 - 2005-12-31 03:45 AM Re: ReadProfileString Used In a Loop?
tylan Offline
Starting to like KiXtart

Registered: 2005-11-17
Posts: 115
Loc: Johnstown, PA
Thanks. I will check it out.
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.136 seconds in which 0.088 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