title: VB.NET - Getting a NaN result, can't figure out why
body: <p>I'm trying to write a simple GPA calculator where the user enters a grade from an item on a combobox (A,B,C,D,F) and the credit hours of the course, and the calculation will output into a textbox. However, I keep getting a NaN result within the textbox and I can't for the life of me understand why. I've only got a bit of programming experience, so I'd appreciate any help!</p>
  
  <pre><code>    Public Class Form1
  
      Public points As Double, hours As Integer
  
      Private Sub btnRecord_Click(sender As Object, e As EventArgs) Handles btnRecord.Click
  
          Dim gpaPoints As Double
          Dim creditHours As Integer
          Dim grade As String
  
          If cmbGrades.SelectedIndex &lt; 0 Then
              MsgBox("Please select a grade.")
              Exit Sub
          ElseIf txtHours.Text = "" Then
              MsgBox("Please enter credit hours.")
          Else
              grade = cmbGrades.SelectedItem
              creditHours = CInt(txtHours.Text)
              gpaPoints = CalcGPA(grade, creditHours)
              points += gpaPoints
              hours += creditHours
              ClearList()
          End If
  
      End Sub
  
      Public Sub ClearList()
          cmbGrades.SelectedIndex = -1
          cmbGrades.Text = "Select a grade"
          txtHours.Text = ""
      End Sub
  
      Public Function CalcGPA(grade As String, creditHours As Integer)
  
          Dim gpaPoints As Double
  
          Select Case (grade)
              Case "A"
                  gpaPoints = 4
              Case "B"
                  gpaPoints = 3
              Case "C"
                  gpaPoints = 2
              Case "D"
                  gpaPoints = 1
              Case Else
                  gpaPoints = 0
  
          End Select
  
          Return gpaPoints
  
      End Function
  
      Private Sub btnGpa_Click(sender As Object, e As EventArgs) Handles btnGpa.Click
  
          Dim calcGpa As Double = points / hours
  
          txtGpa.Text = FormatNumber(calcGpa, 2)
  
      End Sub
  
  End Class
  </code></pre>
  
  <p>I basically have the record button which works fine clearing the list and allows someone to enter a second grade, but the calculate button is not working and I can't figure this out. I sincerely appreciate any help.</p>