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
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
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 :
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With