Why Won't VB Express Edition Trigger LostFocus Event?

  • Thread starter Thread starter dt19
  • Start date Start date
Click For Summary

Discussion Overview

The discussion centers around the issue of the LostFocus event not triggering in Visual Basic (VB) Express Edition when attempting to validate user input in a quadratic equation solver. Participants explore the reliability of event callbacks in different versions of VB and suggest alternative approaches for input validation.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes their implementation of a LostFocus event to validate numeric input in a text box, noting it worked in VB 6.0 but not in VB Express Edition.
  • Another participant suggests that the LostFocus event is not reliable, even in VB 6.0, and recommends using the Validate callback instead, which allows for cancellation of focus transfer.
  • A third participant requests more information about any error messages and their locations to assist in diagnosing the issue.
  • A later reply reiterates that there is no error message; rather, the LostFocus callback simply does not execute, and mentions a historical context of similar issues dating back to VB 3.
  • Participants discuss the addition of the Validate function as a potential solution to the problem of input validation.

Areas of Agreement / Disagreement

Participants express differing views on the reliability of the LostFocus event across VB versions, with some suggesting alternative methods for validation. No consensus is reached on the best approach to handle the issue.

Contextual Notes

Limitations include the lack of clarity on whether the Validate callback is available in VB Express Edition and the historical context of similar issues with event callbacks in 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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
3K
Replies
4
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
18K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 3 ·
Replies
3
Views
13K