So i' new to VB.NET and im making a windows form where the user inputs testscores and the form updates total number of scores added,average score,best score,number of scores.
I also need to validate the user's input not only as a number but also as an integer.I figure i need a while loop to do this and some sub's and functions too. i have the code-so-far-below with the 'If' loop..pardon that...i need to put a while loop..but any more help on validating an integer would help.
Private Sub btnEnter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEnter.Click
Dim bValidEntries As Boolean
Me.ValidateScoreEntry(txttestscore.Text, bValidEntries)
If bValidEntries Then
End If
End Sub
Private Sub ValidateScoreEntry(ByVal txttestscore As String, ByRef ValidEntries As Boolean)
Dim daveragescore, dbestscore As Decimal
Dim itestscore, inumberofscores, itotalscores As Integer
If IsNumeric(txttestscore) Then
If txttestscore >= 0 And txttestscore <= 100 Then
inumberofscores += 1
itotalscores += txttestscore
daveragescore = itotalscores / inumberofscores
txtnumberofscores.Text = inumberofscores
txttotalscores.Text = itotalscores
txtaveragescore.Text = daveragescore
ValidEntries = True
Else : MsgBox("Test Score not between 0 and 100", MsgBoxStyle.Critical, "Error")
End If
Else : MsgBox("Test Score is not a number!", MsgBoxStyle.Critical, "Error")
End If
End Sub
I also need to validate the user's input not only as a number but also as an integer.I figure i need a while loop to do this and some sub's and functions too. i have the code-so-far-below with the 'If' loop..pardon that...i need to put a while loop..but any more help on validating an integer would help.
Private Sub btnEnter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEnter.Click
Dim bValidEntries As Boolean
Me.ValidateScoreEntry(txttestscore.Text, bValidEntries)
If bValidEntries Then
End If
End Sub
Private Sub ValidateScoreEntry(ByVal txttestscore As String, ByRef ValidEntries As Boolean)
Dim daveragescore, dbestscore As Decimal
Dim itestscore, inumberofscores, itotalscores As Integer
If IsNumeric(txttestscore) Then
If txttestscore >= 0 And txttestscore <= 100 Then
inumberofscores += 1
itotalscores += txttestscore
daveragescore = itotalscores / inumberofscores
txtnumberofscores.Text = inumberofscores
txttotalscores.Text = itotalscores
txtaveragescore.Text = daveragescore
ValidEntries = True
Else : MsgBox("Test Score not between 0 and 100", MsgBoxStyle.Critical, "Error")
End If
Else : MsgBox("Test Score is not a number!", MsgBoxStyle.Critical, "Error")
End If
End Sub