#64514 - 2002-04-12 06:49 PM
Create incrementing Variable Names inside a Loop
|
Bonji
Starting to like KiXtart
Registered: 2001-09-28
Posts: 169
Loc: Virginia
|
I'm trying to create incrementing variable names inside a loop with no success. Here's an example of the code I had in mind to make it work...
code:
$I = 0 While $I < 5 DIM $TMPVAR$I $I = $I + 1 Loop
I would want this code to create the following variables...
$TMPVAR0, $TMPVAR1, $TMPVAR2, $TMPVAR3, $TMPVAR4
The problem comes in because variables cannot be used to create variable names. If anyone knows a workaround or another way to accomplish this, I would appreciate it.
Thanks, Ben Dulaney
|
|
Top
|
|
|
|
#64515 - 2002-04-12 06:58 PM
Re: Create incrementing Variable Names inside a Loop
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
How about using execute:
code:
break on
$I = 0
While $I < 5 $=Execute("$$TMPVAR$I = $i") $I = $I + 1 Loop
?"TmpVar2=" $TMPVAR2
exit 1
-Shawn [ 12 April 2002, 18:59: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#64517 - 2002-04-14 06:20 AM
Re: Create incrementing Variable Names inside a Loop
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear Ben,
We advise you to use an array instead of method. It is a very strange way of programming, which make it hard to understand "what is happening" and "what is going wrong in our script". Maintaining becomes also hard.
Please explain: why you prevent this method above array usage.
greetings.
btw: in the past another member try to create also dynamic variables, but his way doesn't have a structure.
|
|
Top
|
|
|
|
#64518 - 2002-04-23 10:27 PM
Re: Create incrementing Variable Names inside a Loop
|
Car guy
Lurker
Registered: 2002-02-11
Posts: 4
Loc: Beaverton, Oregon
|
MCA,
How do you accomplish the above in an array?
_________________________
Keyboard error - press F1 to resume
Dave Lum - dlum@tfc.textron.com
Sr. Network Specialist, TFC-Textron
503.675.5510 / 800-704-5208(fax)
|
|
Top
|
|
|
|
#64519 - 2002-04-25 04:02 PM
Re: Create incrementing Variable Names inside a Loop
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
A possibility is following which was put on by Bryce.
Run on kixtart 4.x
code:
break on DO $temp=ENUMGROUP($index) $groups=$temp+",$groups" $index=$index+1 UNTIL Len($temp) = 0 $groups=split(substr($groups,2,len($groups)),",") REDIM preserve $groups[ubound($groups)-1] ? "Number of groups @userid is a member of = " ubound($groups)+1 FOR EACH $group IN $groups ? $group NEXT
another example for kixtart 3.x
code:
DIM $elements[64] $i=1 WHILE ($i <= 64) $elements[$i]=$i $i=$i+1 LOOP
kixtart 3.x doesn't know REDIM command and $ubound function. Of course we doesn't know what you wnat to assign. "64" is an example value. greetings.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 931 anonymous users online.
|
|
|