Why Won't VB Express Edition Trigger LostFocus Event?

  • Thread starter Thread starter dt19
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 2K views
dt19
Messages
46
Reaction score
0
i'm writing a really simple quadratic equation solver. the code below is to display a messgae if the user inputs something that is not a number into a text input box for one of the coefficients. it worked on VB 6.0 so why won't it work for VB express edition?
txt_x2 is the input box


Private Sub txt_x2_LostFocus()
If IsNumeric(txt_x2.Text) = False Then
MsgBox("Enter a number!", vbOKOnly, "Message")
End If

End Sub
 
Physics news on Phys.org
Actually, it's not a simple question.
Even in VB6 the Lostfocus callback does not work reliably.

Better is the Validate callback.
It occurs before Lostfocus and you can cancel the transfer of focus to another control.
I don't know if it's available in express.

You can put a common function that interrogates all the editable controls for vaild data or empty in the Gotfocus callback of each control that can get focus. This works in all versions of VB.
For the Gotfocus of the "do something button" you may not want to allow empty.
 
It might help us diagnose if you show us the erorr message and location.
 
DaveC426913 said:
It might help us diagnose if you show us the erorr message and location.
For what the OP is talking about there is no error message.
VB just does not issue the callback to the lostfocus function, so any code there does not get executed.

IIRC the first time someone asked someone asked me to find why this code didn't work it was still VB 3.
The problem never did get fixed. Way to go MS.:rolleyes:
However, they did add the validate function.