VBScript Array Element problem

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jhanasik
Newbie
Posts: 11
Joined: Mon Jan 27, 2003 5:56 pm

VBScript Array Element problem

Post by jhanasik » Wed May 25, 2005 10:22 pm

I am using vbscript to load 3 arrays with values from a file. This part works fine as I can watch it load each element. Code is below.



Sub LoadCityIDArray(strCity, strCityName, strCitySiteID, intA)
redim preserve arrCity(intA)
redim preserve arrCityName(intA)
redim preserve arrCItySiteID(intA)
arrCity(intA) = strCity
arrCityName(intA) = strCityName
arrCitySiteID(intA) = strCitySiteID
End Sub
VBEND


When I try to use VBEval to attempt to find a matching entry in the
array I either get a "subscript out of range" error or the first element.
Here is my code.



Let>o=0
Let>q=0
Repeat>o
let>o=o+1
VBEval>ArrCity(0,q),myCity
MessageModal>myCity
MessageModal>city
If>myCity=city
MessageModal>Found it!
Endif
Let>intA=intA+1
Let>q=q+1
Until>o,25




I have searched the forum and tips and tricks on how to iterate through an array using VBEval but I seem to be missing something. I need the value in "city" to match to one of the array elements before continuing.
Anyone have any ideas what I am doing wrong.
Thanks

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu May 26, 2005 6:56 am

Is ArrCity a global array? Post full code. If it is local only then that won't work. Also you'd need to do this:

VBEval>ArrCity(0,%q%),myCity

Since q is a MacroScript variable. Without the % it is seen as literally q which would cause an error unless q was also defined as a VBScript variable.
MJT Net Support
[email protected]

jhanasik
Newbie
Posts: 11
Joined: Mon Jan 27, 2003 5:56 pm

Post by jhanasik » Thu May 26, 2005 5:31 pm

Using the % worked. How dumb of me. After reviewing so many examples one would have thought that I would have figured that out! Thanks for the help.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts