Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all
Creating a macro (procedure) in the Edit module I can sucessfuly set an array like so:
ListOfNames = Array("Name 1","Name 2","Name 3")
However, when I try to make that dynamic and set the names into a string variable and then pass the string variable to the array it does not work.
strOfNames = ("Name 1","Name 2","Name 3")
ListOfNames = Array(strOfNames)
Is there a way to pass the string variable to the array? (What am I doing wrong?)
Thanks
Josh
Try this:
strOfNames = """Name 1"",""Name 2"",""Name 3"""
Thanks for your reply but the expression
strOfNames = """Name 1"",""Name 2"",""Name 3"""
is wrong and cannot be resolved to a string.
It works for me in QV 10 SR6
What can I say? You learn something new every day!
Setting the variable this way does work. (I am surprised that it does work in the Edit module because in any VB IDE this statement produces an error "End of statement expected")
Never the less, it did not pass to the array.
The arguments of the Array() function need to be an array, not a string. Did you see Gysbert's reply? I don't see it in this thread:
What you should probably do instead is get a count of the items you want to add to the array, size the array accordingly and then use a loop to add the items. If you can't get a count of the items and are using something like a while or a for each loop then you can redim the array on each iteration of the loop and add the item. See http://windowsitpro.com/article/vbscript/understanding-vbscript-arrays-5627 for more information on arrays in vbscript.