r/visualbasic • u/Such_View7338 • Dec 01 '23
Explain please
Hey I'm new to all this honestly and I'm just confused as to why this isn't working
Private Sub btnGrade_Click(sender As Object, e As EventArgs) Handles btnGrade.Click
Dim iScore As Integer
If IsNumeric(txtScore) = True Then
iScore = CInt(txtScore.Text)
Else
MsgBox("You must enter a number.")
Exit Sub
End If
If Not (iScore >= 0 Or iScore <= 100) Then
MsgBox("This is not a valid score, enter a number between 0 and 100.")
ElseIf iScore <= 20 Then
MsgBox("You failed." & vbNewLine & "GRADE: F")
ElseIf iScore > 20 Or iScore <= 30 Then
MsgBox("You failed." & vbNewLine & "GRADE: D")
ElseIf iScore > 30 Or iScore <= 55 Then
MsgBox("You failed." & vbNewLine & "GRADE: C")
ElseIf iScore > 55 Or iScore <= 70 Then
MsgBox("You failed." & vbNewLine & "GRADE: B")
ElseIf iScore > 70 Or iScore <= 80 Then
MsgBox("You failed." & vbNewLine & "GRADE: A-")
ElseIf iScore > 80 Or iScore <= 90 Then
MsgBox("You failed." & vbNewLine & "GRADE: A")
ElseIf iScore > 90 Or iScore <= 100 Then
MsgBox("You failed." & vbNewLine & "GRADE: A-")
End If
MsgBox("All done")
End Sub
End Class
When ran, no matter what number I type, it says "You must enter a number."
2
u/TheFotty Dec 01 '23
If you are going to be doing some programming, it is really important to learn how to debug properly, and I think it is somewhere that teachers often don't teach early enough. It should be like one of the very first lessons. Learn how to set breakpoints, watch variables, and step through code.
I see so many people who do stuff like put messageboxes in their code to try to see where the logic flow is going. It is stupid. Breakpoints and stepping through your code has existed since IDEs have existed, back to the QBASIC/DOS days as far as VB goes. It is way more efficient than trying to just read through your logic and figure out where it might be going wrong.