将以1为基数的数组更改为以0为基数的数组 [英] Change Base 1 Array to Base 0 Array

查看:121
本文介绍了将以1为基数的数组更改为以0为基数的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Excel检索数据,并希望使数组保持基于0的值,但是Excel返回1的基数.有没有一种相当简单的方法来将数组从1更改为0的返回值?还是我只需要创建一个循环?

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?

这里是示例代码:

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

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

oData=rng.Value2

推荐答案

循环是最简单的选择.

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.

这篇关于将以1为基数的数组更改为以0为基数的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆