|
-
Oct 7th, 2015, 04:50 PM
#1
Thread Starter
New Member
Message Box error working for one type of error but not all
Good afternoon folks,
I stumbled on this forum during class and thought this would be the best place to get advice (my instructor was very vague and I didn't understand my questions).
The message box says that, "Number cannot be a letter and must be positive".
I have no issue with a negative number setting off the message box, but whenever I put a letter in the text box, no message pops up. I'll post my whole code for situation awareness, but the code that I'm having trouble will be at the bottom.
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btbcalculate.Click
' Declare variables.
Dim intRunner1time As Integer
Dim intRunner2time As Integer
Dim intRunner3time As Integer
Dim strRunner1 As String = String.Empty
Dim strRunner2 As String = String.Empty
Dim strRunner3 As String = String.Empty
' Get input
Try
intRunner1time = CInt(txttime1.Text)
intRunner2time = CInt(txttime2.Text)
intRunner3time = CInt(txttime3.Text)
strRunner1 = txtRunner1.Text
strRunner2 = txtRunner2.Text
strRunner3 = txtRunner3.Text
'Display race results
If intRunner1time < intRunner2time And intRunner1time < intRunner3time And intRunner2time < intRunner3time Then
lblfirst.Text = strRunner1
lblsecond.Text = strRunner2
lblthird.Text = strRunner3
ElseIf intRunner1time < intRunner2time And intRunner1time < intRunner3time And intRunner3time < intRunner2time Then
lblfirst.Text = strRunner1
lblsecond.Text = strRunner3
lblthird.Text = strRunner2
ElseIf intRunner2time < intRunner1time And intRunner2time < intRunner3time And intRunner1time < intRunner3time Then
lblfirst.Text = strRunner2
lblsecond.Text = strRunner1
lblthird.Text = strRunner3
ElseIf intRunner2time < intRunner1time And intRunner2time < intRunner3time And intRunner3time < intRunner1time Then
lblfirst.Text = strRunner2
lblsecond.Text = strRunner3
lblthird.Text = strRunner1
ElseIf intRunner3time < intRunner1time And intRunner3time < intRunner2time And intRunner1time < intRunner2time Then
lblfirst.Text = strRunner3
lblsecond.Text = strRunner1
lblthird.Text = strRunner2
ElseIf intRunner3time < intRunner1time And intRunner3time < intRunner2time And intRunner2time < intRunner1time Then
lblfirst.Text = strRunner3
lblsecond.Text = strRunner2
lblthird.Text = strRunner1
End If
'display name errors
If txtrunner1.Text = String.Empty Then
MessageBox.Show("Please enter a name")
ElseIf txtrunner2.Text = String.Empty Then
MessageBox.Show("Please enter a name")
ElseIf txtrunner3.Text = String.Empty Then
MessageBox.Show("Please enter a name")
End If
'Display negative number and letter error
If Integer.TryParse(txttime1.Text, intRunner1time) And IsNumeric(intRunner1time) And intRunner1time < 0 Then
MessageBox.Show("Number cannot be a letter and must be positve")
ElseIf Integer.TryParse(txttime2.Text, intRunner2time) And IsNumeric(intRunner2time) And intRunner2time < 0 Then
MessageBox.Show("Number cannot be a letter and must be positve")
ElseIf Integer.TryParse(txttime3.Text, intRunner3time) And IsNumeric(intRunner3time) And intRunner3time < 0 Then
MessageBox.Show("Number cannot be a letter and must be positve")
End If
Catch ex As Exception
End Try
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|