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?

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.