VBA Equivalent of ASP 'Execute' Command

  • Thread starter Thread starter The Vision Thing
  • Start date Start date
T

The Vision Thing

Is there a VBA equivalent of ASP's 'Execute' command. I'd like to use such
a command to dynamically declare variables at run-time.

Here's a sample of ASP 'Execute' code.

---------------------------
varID = fp_rs("ID")
varName = fp_rs("Name")
varOccupation = fp_rs("Occupation")

for i = 1 to numFields
Execute("var" & arr_fieldnames(i) & " = fp_rs(""" & arr_fieldnames(i) &
""")"
next
 
The Vision Thing said:
Is there a VBA equivalent of ASP's 'Execute' command. I'd like to use such
a command to dynamically declare variables at run-time.

Here's a sample of ASP 'Execute' code.

---------------------------
varID = fp_rs("ID")
varName = fp_rs("Name")
varOccupation = fp_rs("Occupation")

for i = 1 to numFields
Execute("var" & arr_fieldnames(i) & " = fp_rs(""" & arr_fieldnames(i) &
""")"
next

I think Application.Evaluate is what you are looking for.

/Fredrik
 
Are you executing a different program?

Take a look at Shell in VBA's help.

Are you running a different subroutine?

Application.Run

maybe it.
 
Fredrik Wahlgren said:
I think Application.Evaluate is what you are looking for.

/Fredrik

I don't think Application.Evaluate solves the problem. I want to
dynamically declare variables and assign values like so:-

For i = 1 to Ubound(arrIn)
Dim ("var" & i) as string
("var" & i) = arrIn(i)
Next

Regards,
Wayne C.
 
Dave Peterson said:
Are you executing a different program?

Take a look at Shell in VBA's help.

Are you running a different subroutine?

Application.Run

maybe it.

What I'm trying to do is dynamically declare variables and assign values to
them, like so

For i = 1 to Ubound(arrIn)
Dim ("var" & arrIn(i)) as string
("var" & arrIn(i)) = arrIn(i)
Next

Regards,
Wayne C.
 
I'm not sure there aren't better ways to achieve this - declaring
variables on the fly is not really good practise. You would be much
better off using a dictionary object or array for what you're trying
to do.


Tim.


The Vision Thing said:
Thanks Dave, that's what I needed to know.

Wayne C.
 
Back
Top