#36718 - 2003-02-20 10:15 AM
Combine Variable
|
ladybird
Fresh Scripter
Registered: 2002-08-11
Posts: 19
|
Really need help on this.
I would like to combine 2 variables into 1 new variable.
Example: $total = 3 $Cnt = 0 $var1 = string1 $var2 = string2 $var3 = string3
While $total > $Cnt $Cnt = $Cnt + 1 $newvar = $var + $Cnt <------ ? $newvar Loop
What i would like to have: $newvar should have result as $var1 where is "string1".
Actually, i would like to loop as many as $total variable defined and use $var1, $var2, $var3 when is looping.
Thanks in advance.
|
|
Top
|
|
|
|
#36721 - 2003-02-20 10:41 AM
Re: Combine Variable
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
It took me a couple of minutes to get my head around your post, but I think this is what you want:
code:
$iTotal=3 $sVar1="String 1" $sVar2="String 2" $sVar3="String 3"
For $iCount = 1 To $iTotal $sNull=Execute("$$sNewvar=$$sVar"+$iCount) "$$sNewvar="$sNewvar ? Next
|
|
Top
|
|
|
|
#36723 - 2003-02-20 11:09 AM
Re: Combine Variable
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Here is a slightly different version that doesn't require you to set the "total" variable:
$sVar1="String 1" $sVar2="String 2" $sVar3="String 3"
$iCount=1 While Execute("Exit VarType($$sVar"+$iCount+")") $sNull=Execute("$$sNewvar=$$sVar"+$iCount) "$$sNewvar="$sNewvar ? $iCount=$iCount+1 Loop
|
|
|
Top
|
|
|
|
#36726 - 2003-02-21 02:17 AM
Re: Combine Variable
|
ladybird
Fresh Scripter
Registered: 2002-08-11
Posts: 19
|
Richard has answered my questions. Perfect!!
I just change the variable rather to change the code when everytime the requirement is changed.
Thank You!!
|
|
Top
|
|
|
|
#36728 - 2003-02-21 04:20 AM
Re: Combine Variable
|
ladybird
Fresh Scripter
Registered: 2002-08-11
Posts: 19
|
The reason:
I just change the variable rather to change the code/logic when everytime the requirement is changed.
|
|
Top
|
|
|
|
#36730 - 2003-02-22 07:59 PM
Re: Combine Variable
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 633 anonymous users online.
|
|
|