0

Hello,

I've been working on learning VBScript to make a few useful scripts to work with WinNT and make a more user friendly interface when searching for users on a domain. While doing so, I discovered something interesting about arrays and I'm hoping someone could explain if it's just the way microsoft made VB or if it's something else.

If I decalre an Dim myArray(2), one would think valid subscripts would be myArray(0) and myArray(1), but it's not.

Dim myArray(2)
myArray(0) = "Hello"
myArray(1) = "World"
myArray(2) = " This should give an error"
WScript.echo myArray(0) & " " & myArray(1) & myArray(2)

I would expect the above code to give an error, but it doesn't and it runs perfectly. Does VB allocate an extra subscript to accomodate "making sense" or is that last subscript location used for something else?

3
Contributors
2
Replies
19
Views
6 Months
Discussion Span
Last Post by Reverend Jim
0

Sorry, I don't know VBScript at all. However, is it possible that it is returning null or false or such for any index that doesn't exist, as opposed to throwing an error?

1

When you declare an array in vbScript the indexes go from 0 to the number declared. As silly as that may be, it works the same for vbScript and vb.Net.

Feel free to post any more vbScript questions you may have. It was my main programming language for about 8 years and I haven't quite forgotten it all yet.

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.