Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Crashing On Validation Even With No Errors

Status
Not open for further replies.

RoccoSiffredi

Technical User
Nov 10, 2010
16
GB
I have vba to compare values entered in a textbox.

The code validates (Visual Basic 2010 Express) but hangs when I run it and enter a non numerical value in the TxtInputDays box.

If Not (IsNumeric(TxtInputDays)) Then
MessageBox.Show("Please enter a numerical value")
ElseIf result1 > (TodaysRate * myvar) Then
LblResult.Text = "you will be better off by £" & diff & " if you go with option 1"
ElseIf LblResult.Text = "you will be worse off by £" & -diff & " if you go with option 2" Then
End If

If I remove the first part of the validation and leave :

If result1 > (TodaysRate * myvar) Then
LblResult.Text = "you will make more money by £" & diff & " if you go with option 1"
ElseIf LblResult.Text = "you will make more money by £" & -diff & " if you go with option 2" Then
End If
End Sub

The code doesn't hang.
 
VBA Visual Basic for Applications (Microsoft) Forum <> Visual Basic 2010 Express

so you might want to pop on over to forum796 and ask your question there.
 
Having said that, you might want to tidy up your incorrect code as follows:
Code:
[blue]    If Not (IsNumeric(txtInputDays[b].Text[/b])) Then
        MessageBox.Show("Please enter a numerical value")
    ElseIf result1 > (TodaysRate * myvar) Then
        LblResult.Text = "you will be better off by £" & diff & "  if you go with option 1"
    [b]Else
        LblResult.Text = "you will be worse off by £" & -diff & "  if you go with option 2"[/b]
    End If[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top