# Option Base 0 or Option Base 1?

• Total voters
2

#### Lokai

##### Board Regular
I prefer Option Base 1.
It makes transfer from array-to-sheet and vice-versa less complicated. Option Base 0 is the default but I don't see the practical advantage.
?

### Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

#### dk

##### MrExcel MVP
For me the answer is consistency and not getting confused over what has been set as base 1 and what hasn't. Lots of controls with multiple items (e.g. listboxes, comboboxes) start at zero. Any library you refer to will probably have collections and these are likely to always start at zero. If I know that I should always start at zero then I'm less likely to make a mistake when writing code.

Anyway, I don't think there's a right or a wrong way, it's one of those things which is down to personal preference

#### Juan Pablo González

##### MrExcel MVP
FWIW, VB .Net is "pushing" for 0 based arrays...

#### just_jon

##### Legend
Yeah, 0-based seems to be "in". Wonder why though. The theory of a zero-th unit perhaps? Really don't know. Personally, I prefer base=1 so First=1. Just seems easier to explain to people... 'course, then you've still got to explain why the variable "i" has a value of 11 after --

For i=1 to 10
Next i

#### dk

##### MrExcel MVP

Don't think 0 is "in", it's always been like that. I think it boils down to binary (yawn). With 4 bits for example you can represent a number up to 15 (1+2+4+8). If we count from 1 then that gives us 15 usable numbers but if we count from zero it gives us an extra number free! That's 16 different memory addresses the computer can look at, or 16 bytes of information that can be written to a disk at a time, blah blah. A poor analogy would be giving a postman who's strong enough to carry 16 parcels a bag only big enough to fit 15 in. If he has 16 parcels to deliver then he's going to have to make a trip back to the depot to get his last parcel and he won't be a happy postman.

I promise I won't make another analogy on this board.

#### NateO

##### Legend
My answer is neither, I simply use the default, whether it's 1 or 0 on an array, never having touched the Option Base declaration. If I don't know where the default is, I tend to test the lower and upper boundaries while I'm developing. One trick, say with Resize() could be to add:

(lbound(myArr)-1)*-1

For a consistent 1-base effect.

#### NateO

##### Legend

JPG said:
FWIW, VB .Net is "pushing" for 0 based arrays...
Indeed, maybe understating the matter eh.

If portability to .Net has an impact on your thinking regarding the subject see the following: Use Zero Bound Arrays

#### just_jon

##### Legend
Well, that's a change worth noting.

#### Ivan F Moala

##### MrExcel MVP
Use the default and amend when required.

#### XL-Dennis

##### Well-known Member
Always explicit declaring Option Base 0 or 1 is good coding

If You have 0 apples in real life it means You have no apples but this is not real life and it´s not about how many at all :wink:

If we have 4 apples we can name them in some kind of order like first, second... 0 or 1 based is used to index arrays. The use of 0-based indexing refers to assembly language and all the hardware starts with 0-based addresses.

So when JPG mention that VB.NET push for 0-based it means that MS accept the way things are in the computer-world

There shouldn´t be a need to check the LBound for arrays if we know the basic about arrays in XL. Reading data into arrays from sheets will always return a 1-based array even if we explict states Option Base 0 as the below case shows.

Option Explicit
Option Base 0

Dim rnData As Range
Dim i As Long

Set rnData = Range("A1:A4")

'Wrong way
For i = 0 To 3
'This will erase runtime error 9 - subscription out of range
'as the index 0 does not exist
Next i

'Right way
For i = 1 To 4
Next i

End Sub

Personally I use 0-based and 1-based where they are the most suitable. As the case shown above it is sometime difficult to use 0-based.

So where is the third option based on index start at 1 and second option based on indext start at 0.

I promise I won't make another analogy on this board.
You do

Take care,
Dennis

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,152,094
Messages
5,768,051
Members
425,451
Latest member
JohnBrooksBiddle

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back