Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are array indexes 0-based in VB6?

I'm reviewing an automatic translation of VB6 code to C# and the convertor translated someArray(3) to someArray[3]. But accordingly to the old code documentation it should pick the third element not the fourth as it is doing in the translated version.

Are array indexes 0-based in VB6? Or do they start at 1?

like image 620
Jader Dias Avatar asked Jan 09 '12 11:01

Jader Dias


People also ask

Are Visual Basic arrays zero based?

All arrays must be zero-indexed. In Microsoft Visual Basic 6.0, you can define arrays with the lower bounds and upper bounds set to any integer. In Microsoft Visual Basic . NET, the lower bound of every array dimension is zero (0).

Are arrays indexed from 0?

In computer science, array indices usually start at 0 in modern programming languages, so computer programmers might use zeroth in situations where others might use first, and so forth.

Is array always start with index 0?

An array arr[i] is interpreted as *(arr+i). Here, arr denotes the address of the first array element or the 0 index element. So *(arr+i) means the element at i distance from the first element of the array. So array index starts from 0 as initially i is 0 which means the first element of the array.

Is array index based?

Zero-based array indexing is a way of numbering the items in an array such that the first item of it has an index of 0, whereas a one-based array indexed array has its first item indexed as 1. Zero-based indexing is a very common way to number items in a sequence in today's modern mathematical notation.


2 Answers

Yes - arrays are (generally) 0 based in VB6

The exceptions to this are when the explicit Dim someArray(1 To 10) as Int syntax has been used, or when Option Base 1 is declared at the top of the code module.

It's Collections that aren't - when you loop through Collection objects I'm pretty sure that they are 1 based.

like image 190
Jon Egerton Avatar answered Oct 10 '22 06:10

Jon Egerton


The short answer is that array lower bounds are what you tell them to be.

The default is base 0 (unless overridden by Option Base 1), but you can declare lower bound to any value you want (Dim arr(-42 To 42) is as valid as Dim(3)).

Also, if an array is returned by some object, its lower bound is whatever that object sets it to. For example an Excel Range.Value reference will return a 1 based array.

like image 45
chris neilsen Avatar answered Oct 10 '22 06:10

chris neilsen