Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Ridiculously simple vb problem

  1. Aug 3, 2006 #1
    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
  2. jcsd
  3. Aug 3, 2006 #2


    User Avatar
    Science Advisor
    Homework Helper

    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.
  4. Aug 3, 2006 #3


    User Avatar
    Gold Member

    It might help us diagnose if you show us the erorr message and location.
  5. Aug 4, 2006 #4


    User Avatar
    Science Advisor
    Homework Helper

    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.:uhh:
    However, they did add the validate function.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook