Using a String as Variable Name
Once upon a time, I found a code example that allowed you to use a string as a variable name in Visual Basic 6.0.
The example was extremely simple and worked fine, so I documented it for later use. Then like all good engineers, I placed the document somewhere that it could never be found again.
The example was like SOMETHING("STRING"). So, SOMETHING("MyVar") would be the same as a variable named MyVar.
...
dim tempStr as String
for i = 0 to 5
tempStr = "MyVar" & i
SOMETHING(tempStr) = i 'not an array
next
...
I AM NOT LOOKING FOR OTHER WAYS TO DO THIS.
I AM OBSESSED WITH FINDING THIS EXACT FUNCTION AGAIN.
Thanks
Re: Using a String as Variable Name
You can write script code to kind of do what you want. Normally, used for MATH.
Warning! Dangerous to leave in code. User can do ANYTHING!
Code:
Option Explicit
' Add a reference to Microsoft Script Control 1.0
Private Sub Form_Load()
Dim str1 As String
Dim dbl1 As Double
Dim x As New ScriptControl
Dim z%, a%, q$
z = 55
a = 24
q = "*"
x.Language = "vbScript"
MsgBox Format(x.Eval(z & q & a), "standard")
' ===============================================
str1 = "(5+50)*2/3"
dbl1 = (x.Eval(str1))
MsgBox dbl1
End Sub
Re: Using a String as Variable Name
Have a look at CallByName function or as suggested by dglienna use script control.