Page 1 of 1 1
Topic Options
#50815 - 2000-07-31 08:05 PM Assigning Dynamic Variables With In A Loop
Anonymous
Unregistered


Hey All, Here is a question I could use some help with. How can I assign dynamic variables with in a loop statement? I need to use a loop to parse multiple lines from a file and need to assign line specific variables to each line parsed. Any ideas?? =)

------------------
THANKS
MARK =)

Top
#50816 - 2000-07-31 08:12 PM Re: Assigning Dynamic Variables With In A Loop
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Mark, Hiya
ermmmm, with an array?
ok , i have take a closer look on yer attachments....

Till then

Jochen

_________________________



Top
#50817 - 2000-07-31 09:57 PM Re: Assigning Dynamic Variables With In A Loop
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Mark

Do you want to pass more than one line at the time, and what is the purpose?

Erik

Top
#50818 - 2000-07-31 10:49 PM Re: Assigning Dynamic Variables With In A Loop
Anonymous
Unregistered


if you are thinking how to assign values to variables with a loop ... then beleive me what you need is an array not variables !
Top
#50819 - 2000-08-01 01:38 PM Re: Assigning Dynamic Variables With In A Loop
Anonymous
Unregistered


This is asample of what I'm trying to parse:

[AMAATS200]
active=y

[AMAFTS200]
active=y

[AMALMS200]
active=y

[AMALPS200]
active=y

[AMAPPS200]
active=y

What I would like to do is each time it goes through the loop have it assign a unique variable to to each piece of information that is parsed so AMAATS200 would be $choice1
& AMAPPS200 would be $choice5. Not quite sure what the code for this should look like I have seen examples of array code but don't quite follow how the variables are assigned. DIM $array[$array_count] so in this statement what would the "dynamic variable be?

------------------
THANKS
MARK =)

Top
#50820 - 2000-08-01 02:55 PM Re: Assigning Dynamic Variables With In A Loop
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
I dont know if the sections in your parsing file are servers or domains,
i have chosen to treat them as servers and made the file Server.ini

Server.ini

code:
[AMAATS200]
active=y

[AMAFTS200]
active=y

[AMALMS200]
active=n

[AMALPS200]
active=y

[AMAPPS200]
active=y

In the following code you must replace \\Server\Share\ with the location
you choose for server.ini

DynVar.kix is an example of how to read the ini file into an array.

DynVar.kix

code:

Dim $SrvArray[50] ; Maximum number of sections 50
Dim $Sections, $Section, $idx, $Pos, $Count

$Sections = ReadProfileString("\\Server\Share\Server.ini","","") ; Read all section names from Server.ini
$idx = 1 ; Array index number
$Count = 0
While $Sections <> ""
$Pos = InStr($Sections, Chr(10)) ; Sections are separeted by and ends with linefeed character
$Section = SubStr($Sections,1,$Pos - 1)
$Sections = SubStr($Sections,$Pos + 1, Len($Sections) - $Pos)
$SrvArray[$idx] = $Section ; Place section name in $SrvArray
$idx = $idx + 1
$Count = $Count + 1 ; Number of entries in $SrvArray
Loop

; Run through all sections, and read value for action
$idx = 1
While $idx <= $Count
$Action = ReadProfileString("\\Server\Share\Server.ini",$SrvArray[$idx],"active")
? $SrvArray[$idx] + " Active = " + $Action
; Insert code to execute depending of value of $Action, If $Action = "y"
$idx = $idx + 1
Loop

Get $x ; Remove this line when done testing

Return


Erik

[This message has been edited by kholm (edited 01 August 2000).]

Top
#50821 - 2000-08-01 05:19 PM Re: Assigning Dynamic Variables With In A Loop
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Hey Mark!

Maby I could shed some light on the subject

Mark let me know if i got this right or not.....

Mark contacted me by email last week asking if i could help out with building an array, and we got that part ironed out, the array is nice an populated, but the data inside the array goes something like this.

$array[0] = "0. AMAATS200 = ACTIVE"
$array[1] = "1. AMAFTS200 = ACTIVE"
$array[2] = "2. AMALMS200 = ACTIVE"
...

Mark is this still true?

What i think he wants to do is pull this information back out and make it into a set useful variables.

What i was going to tell him to do, but i never got the chance yesterday because of a dead computer(MINE!!!), was to


  1. tell him to build the array using a delimiter of some sort something like | |
  2. then use the following code to break the array data down to usable variables.

mark using the code that you send me last week, i changed the line

$array[$num] = "$num. $server = $dsp"

to be

$array[$num] = "$num| |$server| |$dsp"

$array[0] would = "0| |AMAATS200| |ACTIVE"


code:

$delim = "| |"
$temp = $array[0]

$a = substr("$temp",1,instr("$temp","$delim")-1)
$temp = substr("$temp",instr("$temp","$delim")+len("$delim"),len("$temp"))
$b = substr("$temp",1,instr("$temp","$delim")-1)
$c = substr("$temp",instr("$temp","$delim")+len("$delim"),len("$temp"))

? $a
? $b
? $c

exit


Bryce

Top
#50822 - 2000-08-02 02:00 PM Re: Assigning Dynamic Variables With In A Loop
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
I must say :

Bryce works with the speed o' light for others !!!

i have just detached the attachments today
(yep, i got it too)
and he comes up with a solution...

Hats off to Bryce!

Jochen

_________________________



Top
#50823 - 2000-08-02 02:57 PM Re: Assigning Dynamic Variables With In A Loop
Anonymous
Unregistered


Yes Bryce is the BOMB

------------------
THANKS
MARK =)

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
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.123 seconds in which 0.097 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