Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Base 1 Array to Base 0 Array

I'm retrieving data from Excel and would like to keep my arrays 0 based but Excel returns 1 base. Is there a fairly simple way to return change the array from 1 to 0 base? Or do I just need to create a loop?

Here's an example code right here:

dim oData(,) as object
dim rng as range
dim wks as worksheet = xlApp.Activeworkbook.sheets(Sheet1)

rng=wks.Range("A1:B2")

oData=rng.Value2
like image 440
Jon49 Avatar asked Jan 31 '12 20:01

Jon49


People also ask

What is the option base of an array?

It is declared at module level and is valid only for the current module. By default (and thus if no Option Base is specified), the Base is 0. Which means that the first element of any array declared in the module has an index of 0. If Option Base 1 is specified, the first array element has the index 1

What is the base of an array in Python?

By default (and thus if no Option Base is specified), the Base is 0. Which means that the first element of any array declared in the module has an index of 0. If Option Base 1 is specified, the first array element has the index 1 Example in Base 0 :

What is array indexing 0-based or 1-based?

Array Indexing: 0-based or 1-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.

Does the split function create an array with a zero-based index?

It should be noted that the Split function always creates an array with a zero-based element index regardless of any Option Base setting. Examples on how to use the Split function can be found here


1 Answers

A loop is the simplest option.

Dim target as string(0 to oData.Length - 1)

For index = 1 to oData.Length 
   target(index - 1) = oData(index)
Next

Thats from memory and not tested but it's obvious enough.

like image 181
Carl Onager Avatar answered Oct 18 '22 13:10

Carl Onager