声明数组& U / L界限 - 冲突信息 [英] Declare Array & U/L Bound - Conflicting Information

查看:64
本文介绍了声明数组& U / L界限 - 冲突信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN声明在声明数组时,括号中的数字是数组的最高索引号。


昏暗的学生(6)因为Integer在数组中确实产生了7个"盒子",最后一个盒子的索引为6.

见:https:/ /msdn.microsoft.com/en-us/library/wak0wfyt.aspx



根据我的知识和其他资源,(6)实际上意味着总共6个盒子!所以最低的盒子索引是学生(0),最高的是学生(5)。哪个是正确的?
$


说到LBound和UBound,这个对象分别返回数组的最低索引和最高索引吗?


例如:学生(6)

UBound(学生)= 5


LBound(学生)= 0

解决方案

该行


昏暗的学生(6)作为整数


声明一个默认下限为0且上限为6的数组,因此是一个包含7个元素的数组。


有一个例外:如果你包含一个行


选项基础1


位于模块顶部,数组的默认下限为1在这种情况下,行


昏暗的学生(6)作为整数


声明一个较低的数组绑定1和上限6,即6个元素的数组。


或者,您可以明确声明下限和上限:


<强>昏暗的学生(3 T o)作为整数


声明一个下限为3且上限为7的数组,即一个包含5个元素的数组。


MSDN states that when declaring an array, the number in the brackets is the highest index number of the array.
Dim students(6) As Integer really produces 7 'boxes' in the array, with the last box indexed as 6.
see: https://msdn.microsoft.com/en-us/library/wak0wfyt.aspx

From my knowledge and other resources, the (6) actually means 6 boxes total! So the lowest box index would be students(0) and the highest would be students(5). Which is correct?

When it comes to LBound and UBound, does this object return the lowest index and highest index, respectively, of the array?

For example: students(6)
UBound(students) = 5

LBound(students) = 0

解决方案

The line

Dim students(6) As Integer

declares an array with the default lower bound of 0 and an upper bound of 6, so an array of 7 elements.

There is one exception: if you include a line

Option Base 1

at the top of the module, the default lower bound of arrays will be 1 instead of 0. In that case, the line

Dim students(6) As Integer

declares an array with lower bound 1 and upper bound 6, i.e. an array of 6 elements.

Alternatively, you can declare both the lower and upper bounds explicitly:

Dim students(3 To 7) As Integer

declares an array with lower bound 3 and upper bound 7, i.e. an array with 5 elements.


这篇关于声明数组&amp; U / L界限 - 冲突信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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