Search code examples
vb.netarraysexcelimport-from-excel

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

Solution

  • 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.