contents of a variable to change other variables? heh

Posted by Gore on Fri 05 Nov 2004 05:28 PM — 7 posts, 28,384 views.

#0
Sorry about the shoddy subject, couldn't figure out what would be best.

This may be a little far out there, but I have no clue if it's possible, or how to do it on my own.

What I'm curious, is, if you can say, use the contents of a variable to modify a variable who's name is the contents of the variable.

Say you have variable varContents, and it contains "varAffliction", is there any to change varAffliction with varContents?
USA #1
Variables:
pointer contains: "target"
value contains: "data"
target contains: "nothing"

setvariable "@pointer", "@value"
(with expand variables)

afterwards:
Variable:
target contains: "data"

setvariable getvariable("pointer"), getvariable("data")

also works.
Amended on Fri 05 Nov 2004 09:04 PM by Flannel
#2
what about script side variables?
USA #3
You can use Execute (or executeglobal) to construct a string (which uses the values of the variable) and then execute it.

I believe thats the only way, since VBScript doesnt do passing by reference/value.
Greece #4
Actually it does, myFunc (ByRef var1, ByVal var2)
#5
I've been trying to figure out what you mean, but I don't think I have a clue.. I looked up execute vbscript on google.com but I just received a bunch of server stuff I think.

Could you elaborate, or would it be best to just use client side variables for this?
USA #6
Theres a good example in the VBScript Doc.

Execute also changes the scope of variables, so you'll have to be aware of that (see the doc on it).

Heres two examples in the documentation (multiline, and single line):

Execute "Sub Proc2: Print X: End Sub"

and...

S = "Sub Proc2" & vbCrLf
S = S & " Print X" & vbCrLf
S = S & "End Sub"
Execute S

ExecuteGlobal is used in the same way, it just changes scope. Look up the details.
(the doc is the one you can download on the same page as the script functions, Microsoft Script Host Documentation, it also has the regexp guide and some other things (Including JScript, which makes searching somewhat troublesome at times).)