|
-
September 15th, 1999, 05:32 AM
#1
LostFocus Handling
Hi all,
I am wondering how to force execution of LostFocus Event handler before the event causing it (mouse click on an other control for example); any idea ?
Thanks
Ahmed
-
September 15th, 1999, 06:23 AM
#2
Re: LostFocus Handling
if you need this for input validation, better check out the Validate Event in VB 6!
-
September 15th, 1999, 09:07 AM
#3
Re: LostFocus Handling
Actually I am using VB4 for this code !!
Any solution ?
-
September 15th, 1999, 09:56 AM
#4
Re: LostFocus Handling
For validation purposes in VB prior to version 6 I used to use this technic:
private intFocus as Integer
private Sub Text1_LostFocus()
If IsTextValid(Text1) = false And (intFocus = -1 Or intFocus = Text1.TabIndex) then
MsgBox "Not valid data in Text1.", , "Warning!"
intFocus = Text1.TabIndex
Text1.SetFocus
else
intFocus = -1
End If
End Sub
private Sub Text2_LostFocus()
If IsTextValid(Text2) = false And (intFocus = -1 Or intFocus = Text2.TabIndex) then
MsgBox "Not valid data in Text2.", , "Warning!"
intFocus = Text2.TabIndex
Text2.SetFocus
else
intFocus = -1
End If
End Sub
private Function IsTextValid(txt as Control) as Integer
'this function analizes contents of the text property of the control (except maskedit box)
If txt.Text = "" then
IsTextValid = false
else
IsTextValid = true
End If
End Function
To test place 2 text boxes on the form with text properties = "" and try to change the focus. Until you enter anything you will not be able to do that. You can customize IsTextValid function to do everything you want.
HTH
Vlad
-
September 15th, 1999, 10:02 AM
#5
Re: LostFocus Handling
private Sub Text1_LostFocus()
If Text1.Text = "" then
MsgBox "bad: field must be filled"
DoEvents ' important
Text1.SetFocus
End If
End Sub
-
September 16th, 1999, 05:52 AM
#6
Re: LostFocus Handling
Thanks For All repliers; it worked fine (for controls).
For Menu Commands I had to do more stuff.
Ahmed
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
|