Change Base 1 Array to Base 0 Array

£可爱£侵袭症+ 提交于 2020-01-02 02:00:09

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/9086229/change-base-1-array-to-base-0-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!