off the top of my head ...
dim ctl as textbox
for each ctl in me
if typeof ctl is textbox then
if len(ctl.text) = 0 then
msgbox "what part of 'enter 5 numbers' don't you understand?"
ctl.setfocus
exit for
end if
end if
next ctl
--
Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Roy Riddex" <EMAIL REMOVED> wrote in message
news:f68Cb.29947$EMAIL REMOVED...
: 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_Click()
: 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(Index).Text
: Next Index
: End If
: End Sub
:
: Private Sub cmdDisplayArray_Click()
: Dim Index As Integer
: For Index = 1 To 5
: lblNumbers(Index).Caption = Numbers(Index)
: Next Index
: End Sub
:
: