Array blowing up

B

Bill

For some reason, when I try to run the following array, I'm getting an
error:


dim cat(0)

cat(0)="0407"
cat(1)="0102"

'I will be adding more to this array, but just trying with two for
starts.

for counter = 0 to 1

itno=cat(counter)

'I get an error when it runs through this function

Function rightvar(theVar,lengthNeeded)
Dim sResult
sResult=theVar
if Len(theVar)< lengthNeeded then sResult= String(lengthNeeded -
Len(theVar)," ")& theVar
rightvar=sResult
End Function


Can someone help me understand why?

Thanks.
 
M

Manohar Kamath [MVP]

You created an array to hold one item, but are filling it with two items,
perhaps that's why the error. Try

Dim Cat(1)

The "1" represents the maximum, zero-based, index you can have in the array.
In this case 1 means 0, 1 = 2 items.
 
D

Dave Anderson

Function rightvar(theVar,lengthNeeded)
Dim sResult
sResult=theVar
if Len(theVar)< lengthNeeded then sResult= String(lengthNeeded -
Len(theVar)," ")& theVar
rightvar=sResult
End Function

That's the oddest indentation scheme I've yet seen.

As for your errors, read up on Dim, ReDim and ReDim Preserve...
http://msdn.microsoft.com/library/en-us/script56/html/vsstmdim.asp
http://msdn.microsoft.com/library/en-us/script56/html/vsstmredim.asp

....and then tell us what kind of error you get when trying your rightvar
function.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top