Why Won't VB Express Edition Trigger LostFocus Event?

  • Thread starter Thread starter dt19
  • Start date Start date
AI Thread Summary
The discussion centers on issues with a quadratic equation solver in Visual Basic Express Edition, specifically regarding the handling of non-numeric input in a text box (txt_x2). The original code uses the LostFocus event to display a message if the input is not a number, which worked in VB 6.0 but is unreliable in VB Express Edition. It is suggested that the Validate callback is a better option, as it occurs before LostFocus and can prevent focus transfer if the input is invalid. There's a recommendation to implement a common function to check all editable controls for valid data in the GotFocus callback of each control. The conversation also notes that the LostFocus event may not trigger correctly, leading to unexecuted code, and mentions that this issue has persisted since earlier versions of VB.
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
 
Technology 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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
2
Views
2K
Replies
10
Views
3K
Replies
4
Views
2K
Replies
4
Views
6K
Replies
6
Views
3K
Replies
9
Views
4K
Replies
3
Views
13K
Back
Top