将按钮添加到数组中时,索引超出了界限 [英] Index was outside the bounds while add button into an array

查看:63
本文介绍了将按钮添加到数组中时,索引超出了界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我尝试将我的按钮存储到一个数组中

但是它会弹出一条错误消息并声明该索引超出阵列范围



我尝试过的事情:



hello

I try to store my buttons into an array
but it keep pop out an error message and state that the index was outside the bounds of array

What I have tried:

dim _buttonArray() as button
dim _button as button

_buttonArray = {}
_button = new button

for i as integer = 0 to 2

with _button
'some setting for my button
end with

_buttonArray(i) = _button

next

推荐答案

指定前面数组的大小:
Dim _buttonArray() As Button = New Button(2) {}

然后,循环直到数组大小

then, loop till the array size

For i As Integer = 0 To _buttonArray.Length - 1

不要忘记删除

_buttonArray = {}


请在循环内实例化你的按钮



Please instantiate your button inside loop

for i as integer = 0 to 2

_button = new button

with _button
'some setting for my button
end with

_buttonArray(i) = _button

next





还要定义按钮数组的大小。



Also define the size of the array of button.


这篇关于将按钮添加到数组中时,索引超出了界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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