J
Joshua Cruz 16
Guest
Good morning i am coding a program and i am currently running into and issue!! I need help telling visual basic that the grade i enter into a text box can only be 0 - 100, if i enter ex."1001" the program will just crash!
THIS IS WHAT I HAVE!
'Name: Joshua Cruz
'Date: 10/29/18
Option Strict Off
Public Class Form1
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'This event closes the form.
Close()
End Sub
''
Private Sub btnAvg_Click(sender As Object, e As EventArgs) Handles btnAvg.Click
'Declare each variable
Dim grade As String
Dim grade2 As String
Dim grade3 As String
'Assigning variables
grade = txt1.Text
grade2 = txt2.Text
grade3 = txt3.Text
'Simple adding and dividing to equal average
txtAverage.Text = (grade + +grade2 + +grade3) / 3
If txt1.Text.Length >= 4 Then
MessageBox.Show("Enter a number between 0 and 100")
End If
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
'Declare variables
Dim letter As String
Dim score As Double
score = txtAverage.Text
letter = txtGrade.Text
'Nested if which determines your average and converts into a letter grade.
If score >= 90 And score <= 100 Then
letter = "A"
ElseIf score >= 80 And score < 90 Then
letter = "B"
ElseIf score >= 70 And score < 80 Then
letter = "C"
ElseIf score >= 60 And score < 70 Then
letter = "D"
Else
letter = "F"
End If
'Wont print out into grade box
txtGrade.Text = letter
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txt1.Clear()
txt2.Clear()
txt3.Clear()
txtAverage.Clear()
txtGrade.Clear()
txt1.Focus()
End Sub
End Class
Continue reading...
THIS IS WHAT I HAVE!
'Name: Joshua Cruz
'Date: 10/29/18
Option Strict Off
Public Class Form1
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'This event closes the form.
Close()
End Sub
''
Private Sub btnAvg_Click(sender As Object, e As EventArgs) Handles btnAvg.Click
'Declare each variable
Dim grade As String
Dim grade2 As String
Dim grade3 As String
'Assigning variables
grade = txt1.Text
grade2 = txt2.Text
grade3 = txt3.Text
'Simple adding and dividing to equal average
txtAverage.Text = (grade + +grade2 + +grade3) / 3
If txt1.Text.Length >= 4 Then
MessageBox.Show("Enter a number between 0 and 100")
End If
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
'Declare variables
Dim letter As String
Dim score As Double
score = txtAverage.Text
letter = txtGrade.Text
'Nested if which determines your average and converts into a letter grade.
If score >= 90 And score <= 100 Then
letter = "A"
ElseIf score >= 80 And score < 90 Then
letter = "B"
ElseIf score >= 70 And score < 80 Then
letter = "C"
ElseIf score >= 60 And score < 70 Then
letter = "D"
Else
letter = "F"
End If
'Wont print out into grade box
txtGrade.Text = letter
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txt1.Clear()
txt2.Clear()
txt3.Clear()
txtAverage.Clear()
txtGrade.Clear()
txt1.Focus()
End Sub
End Class
Continue reading...