I am having problems creating a multi-dimensional control array (specifically, labels) in VB6. I also want to do this entirely from the code, without creating objects on the form and copy-pasting. I know to create the first label, index (0,0) , using "Set", and then use "Load" to create the other labels. However, i am getting "Subscript out of range" as an error message when i run it. My current code is this:
_______________ _______________ ______________
Option Explicit
Dim columns, rows As Integer
Dim Square() As Control
Dim size As Integer
-----------------------------------------------------------
Private Sub Form_activate()
Dim colcount, rowcount As Integer
ReDim Square(0, 0)
Set Square(0, 0) = frmMineSweeper. Controls.Add("V B.Label", "Square", frmMineSweeper)
For rowcount = 0 To rows
For colcount = 0 To columns
If (colcount <> 0) Or (rowcount <> 0) Then
Load Square(colcount , rowcount)
End If
With Square(colcount , rowcount)
.Height = size
.Width = size
.Top = 10 + size * rowcount
.Left = 10 + size * colcount
.Visible = True
.BackColor = vbBlue
.Caption = "N"
End With
Next colcount
Next rowcount
End Sub
---------------------------------
Private Sub Form_Load()
columns = 10
rows = 10
size = 500
End Sub
_______________ _______________ _______________
Any help is appreciated!
_______________ _______________ ______________
Option Explicit
Dim columns, rows As Integer
Dim Square() As Control
Dim size As Integer
-----------------------------------------------------------
Private Sub Form_activate()
Dim colcount, rowcount As Integer
ReDim Square(0, 0)
Set Square(0, 0) = frmMineSweeper. Controls.Add("V B.Label", "Square", frmMineSweeper)
For rowcount = 0 To rows
For colcount = 0 To columns
If (colcount <> 0) Or (rowcount <> 0) Then
Load Square(colcount , rowcount)
End If
With Square(colcount , rowcount)
.Height = size
.Width = size
.Top = 10 + size * rowcount
.Left = 10 + size * colcount
.Visible = True
.BackColor = vbBlue
.Caption = "N"
End With
Next colcount
Next rowcount
End Sub
---------------------------------
Private Sub Form_Load()
columns = 10
rows = 10
size = 500
End Sub
_______________ _______________ _______________
Any help is appreciated!
Comment