Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Help! - Arrays and Variables

Status
Not open for further replies.

feathers

IS-IT--Management
Nov 8, 2002
4
ZA
Thanks in advance!

Okay, so I have an array:

dim myArray(2)
myArray(0) = "hello"
myArray(1) = "goodbye"

then I need to make a variable by taking the string value of one of my array elements, adding it to another string, and setting it to a value.

So, what I tried to to was:
myArray(0) & "John" = "string"

...but that doesn't work

Any ideas of the syntax to create a new variable this way?

THANK YOU!!!
-
 
This can get nasty. Look at this example:
Code:
Dim a(1)
Dim sNewVar

a(0) = "var"

sNewVar = a(0) & "Test"
Execute "Dim " & sNewVar & ":" & _
        sNewVar & "=""value for the variable"""

MsgBox varTest
Execute "MsgBox " & snewVar
You can use the [red]Execute[/red] statement to carry out the VBScript contained within a string. Here I first built a string with the name for the new variable from an array element and a literal.

Then I Executed a string made by concatenating this string with other stuff to make the line of VBScript:
Code:
Dim varTest:varTest="value for the variable"
As you can see, you can directly use this new variable in your script if you already know what it is going to end up being called as I show with the first MsgBox call above. But if a(0) was not "var" then this MsgBox call doesn't work.

But since generally a(0) would have some unpredictable stuff in it (thus the reason for doing this at all), you have to use Executes every time you want to reference it. As shown above in my second MsgBox call.

Not sure why the heck you want to do this, but it will work.

Good luck!
 
dim sStringOne
dim myArray(2)
myArray(0) = "hello"
myArray(1) = "goodbye"

sStringOne = myArray(0) & "string"
'sStringOne will now be "hellostring"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top