Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 16-Feb-17 22:30pm

Specify the size of the array out front:
Dim _buttonArray() As Button = New Button(2) {}
then, loop till the array size
For i As Integer = 0 To _buttonArray.Length - 1
Not to forget to remove
_buttonArray = {}
 
Share this answer
 
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900