|
-
Jan 11th, 2000, 09:15 PM
#1
Thread Starter
Member
Say i have 5 textboxes and in each textbox different data must be entered.(string,integer etc.)
What must i do if i want to let a button appear immediatly after ALL the textboxes was filled in correctly.
Must I use the validation event.HOW?
-
Jan 11th, 2000, 09:35 PM
#2
Member
You would use what's called Form-Level validation. You can set the Form's KeyPreview property to 'True' so that the Form KeyUp, KeyDown, and KeyPress events fire before the control's KeyUp, KeyDown, and KeyPress events. You can then loop thru all of the text boxes on your form and check to see that they are full before making the command button enabled or visible. In this example, my project has several textboxes and a command button called cmdDone:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
'make sure all textboxes have data in them and enable 'Done'
Dim cntrl As Control
Dim bEnabled As Boolean
bEnabled = True 'set to enabled
For Each cntrl In Controls
If TypeOf cntrl Is TextBox Then
If cntrl.Text = "" Then
bEnabled = False
End If
End If
Next cntrl
'now set the enabled property of the command button
cmdDone.Enabled = bEnabled
End Sub
-
Jan 11th, 2000, 09:50 PM
#3
Lively Member
This example comes out of the help and show how to use the validate event
code:
Private Sub Text1_Validate(KeepFocus As Boolean)
' If the value is not a date, keep the focus, unless the user
' clicks Help.
If Not IsDate(Text1.Text) Then
KeepFocus = True
MsgBox "Please insert a date in this field.", , "Text1"
End If
End Sub
Private Sub Text2_Validate(KeepFocus As Boolean)
' If the value is a number larger than 10, keep the focus.
If Not IsNumeric(Text2.Text) Or Val(Text2.Text) > 10 Then
KeepFocus = True
MsgBox _
"Please insert a number less than or equal to 10.", , "Text2"
End If
End Sub
-
Jan 12th, 2000, 12:41 PM
#4
Try this....
You have 5 textboxes start with index 0 to 4
Private Sub Text1_change(Index As Integer)
dim i as integer
dim intnumber as integer
intnumber = 0
for i = 0 to text1.count - 1
if not text1.item(i).text = empty then
intnumber = intnumber + 1
end if
next
if intnumber = text1.count then
'show your commandbutton here
else
'hide your commandbutton here
end if
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|