Sign in to follow this  
Followers 0
mark2004

Use of the execute function

6 posts in this topic

I'm trying to figure out how to dynamically create a variable with the execute statement. The simple code example below

does not set the variable $tempadd3 equal to 5 as I intended. Is this an improper use of the execute function??? If so, can I

do what I am trying to do in a different way??

Dim $tempadd3

$counter=3

$tempstr="$tempadd" & $counter & "=5" ;;;creates the string "$tempadd3=5"

Execute($tempstr)

MsgBox(0,"",$tempadd3)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

???

Dim $tempadd3
$counter=3
$tempadd3 = Execute("$counter +2")
MsgBox(0,"",$tempadd3)
oÝ÷ ÚêܡצjG¬Ç°«l¡ëÞ®Øb²+-ç±jjezÞÅç.µæ®¶­s`¢b33c¶Ó¢b33c·cÔWV7WFRgV÷C²b33c¶³gV÷C²²b33c·b26WBFò
Edited by Thatsgreat2345

Share this post


Link to post
Share on other sites

What is so hard to understand?

The code itself is just a simple way to illustrate the problem. I want to create the variables $var1, $var2......$varX and set them

equal to something dynamically in the code. I will not know what X is until I process some information. It may be 5 or it may

be 500. So, I need some way of looping through and creating/assigning values to the new $varX variables.

Clear as mud right??...;>

Share this post


Link to post
Share on other sites

I made this a good while back as an example for myself. I think this is what you're after. Keywords being Assign and Eval.

For $i = 1 To 5
    Assign('var' & $i, 'this is var' & $i)
Next

For $i = 1 To 7
    If IsDeclared('var' & $i) Then
        MsgBox(0, '', Eval('var' & $i))
    Else
        MsgBox(0, '', 'var' & $i & ' does not exist.')
    EndIf
Next

I've never actually ever had to do something like this before, though, and I still think you'd be better off reading to/from an array.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0