Why Won't VB Express Edition Trigger LostFocus Event?

  • Thread starter dt19
  • Start date
In summary, When writing a quadratic equation solver, a code was provided to display a message if the user inputs a non-numeric value into the text input box for one of the coefficients. This code worked on VB 6.0 but not on VB express edition, as it was unreliable even in VB6. A better solution is to use the Validate callback, which occurs before Lostfocus and allows for the cancellation of transfer of focus. This solution may not be available in express. Another option is to use a common function in the Gotfocus callback of each control that can get focus, which works in all versions of VB. However, for the "do something" button, it may be necessary to not allow empty values. There is no error
  • #1
dt19
47
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
 
Technology news on Phys.org
  • #2
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.
 
  • #3
It might help us diagnose if you show us the erorr message and location.
 
  • #4
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.
 

FAQ: Why Won't VB Express Edition Trigger LostFocus Event?

What is a "Ridiculously simple vb problem"?

A "Ridiculously simple vb problem" is a term used to describe a very basic and straightforward problem that can be solved using the Visual Basic programming language.

How can I solve a "Ridiculously simple vb problem"?

To solve a "Ridiculously simple vb problem", you can use the built-in tools and functions of Visual Basic, such as loops, conditionals, and variables. It is also helpful to have a basic understanding of the language syntax and logic.

What are some examples of "Ridiculously simple vb problems"?

Examples of "Ridiculously simple vb problems" include calculating the sum of two numbers, displaying a message on the screen, and creating a simple calculator program.

Do I need any prior programming experience to solve a "Ridiculously simple vb problem"?

No, you do not need any prior programming experience to solve a "Ridiculously simple vb problem". However, having some basic knowledge of programming concepts can make it easier to understand and solve the problem.

Where can I find resources to help me solve a "Ridiculously simple vb problem"?

There are many online resources available, such as tutorials, forums, and documentation, that can help you solve a "Ridiculously simple vb problem". You can also consult with other programmers or join online communities to get assistance and support.

Similar threads

Replies
2
Views
1K
Replies
10
Views
2K
Replies
4
Views
2K
Replies
4
Views
17K
Replies
4
Views
6K
Replies
6
Views
3K
Replies
9
Views
4K
Replies
4
Views
12K
Back
Top