Working on another assignment and ran into a snag. I am writing the code and testing each routine. When I compile and test and I unable to close the error window
What am I doing wrong
Option Strict On 'Enforces strict data typing
Public Class frmHockeyStats
Dim strName As String
Dim intSeason, intGoals, intAssist As Integer
Private Sub btnGetStats_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnGetStats.Click
'Accept and Validate Name box is not empty
Do While True
' strName = Me.txtName.Text
If String.IsNullOrEmpty(strName) = True Then
MessageBox.Show("Name must be provided", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Exit Do
End If
Loop
'Accept and Validate Season
Do While True
If Integer.TryParse(Me.txtSeasons.Text, intSeason) = False Then
MessageBox.Show("Season Must be a Number", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.txtSeasons.Focus()
Me.txtSeasons.SelectAll()
Else
End If
If intSeason > 0 AndAlso intSeason <= 20 Then
btnGetStats.Enabled = True
Else
Exit Do
End If
Loop
End Sub
'------------------------------------------------------------------------
'btnExit Click Event Procedure.
'1. Closes the form.
'
'Parameters:
' Standard (IDE-supplied)
'
'Calling procedure (example):
' When user clicks on "Exit" button (btnExit)
'------------------------------------------------------------------------
Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnExit.Click
Me.Close()
End Sub
'btnClear Click Event Procedure.
' When the Clear button is selected, the values are cleared
Private Sub btnClear_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnClear.Click
txtName.Text = ""
txtSeasons.Text = ""
txtGoals.Text = ""
txtAssist.Text = ""
lstSeason.Items.Clear()
End Sub
End Class
Open in new window
You have an infinite loop because your condition is hard-coded to True. This is not tragic considering you have an Exit Do in the Else clause. However, think about this: If the Else clause is never entered (which means the If clause was entered), how can you ever break out of the loop based on your current code?