Jump to content

Use of the execute function


Recommended Posts

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


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



Link to comment
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??...;>

Link to comment
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)

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

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.

Link to comment
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...