2nd post of the day! I'm just learning about Arrays at College and have met
a problem. I have 5 text boxes for number input, a command button to add the
numbers to the array, and a command button which displays the array contents
in 5 labels. My program works fine. The problem is that I use a simple If
statement to check for any empty boxes. I've to cut the IF statement and use
a For Each...Next statement to check for empty text boxes but I'm struggling
to apply this method. The book also tells me to declare a variable 'Dim
MyTextBox As TextBox', I've never came across this variable type before.
I'll post my working version of the program and hopefully someone can help
me out.
Option Explicit
Dim Numbers(1 To 5) As Integer
Private Sub cmdAddToArray_C lick()
Dim Index As Integer
If (txtNumbers(1). Text = "") Or (txtNumbers(2). Text = "") Or
(txtNumbers(3). Text = "") Or (txtNumbers(4). Text = "") Or
(txtNumbers(5). Text = "") Then
MsgBox "You have not entered 5 numbers"
Else
For Index = 1 To 5
Numbers(Index) = txtNumbers(Inde x).Text
Next Index
End If
End Sub
Private Sub cmdDisplayArray _Click()
Dim Index As Integer
For Index = 1 To 5
lblNumbers(Inde x).Caption = Numbers(Index)
Next Index
End Sub
a problem. I have 5 text boxes for number input, a command button to add the
numbers to the array, and a command button which displays the array contents
in 5 labels. My program works fine. The problem is that I use a simple If
statement to check for any empty boxes. I've to cut the IF statement and use
a For Each...Next statement to check for empty text boxes but I'm struggling
to apply this method. The book also tells me to declare a variable 'Dim
MyTextBox As TextBox', I've never came across this variable type before.
I'll post my working version of the program and hopefully someone can help
me out.
Option Explicit
Dim Numbers(1 To 5) As Integer
Private Sub cmdAddToArray_C lick()
Dim Index As Integer
If (txtNumbers(1). Text = "") Or (txtNumbers(2). Text = "") Or
(txtNumbers(3). Text = "") Or (txtNumbers(4). Text = "") Or
(txtNumbers(5). Text = "") Then
MsgBox "You have not entered 5 numbers"
Else
For Index = 1 To 5
Numbers(Index) = txtNumbers(Inde x).Text
Next Index
End If
End Sub
Private Sub cmdDisplayArray _Click()
Dim Index As Integer
For Index = 1 To 5
lblNumbers(Inde x).Caption = Numbers(Index)
Next Index
End Sub
Comment