我坚持这个要求我使用结构并生成包含2种数据类型的数组的hw问题:成绩所需的最小点数和实际成绩字母的字符串。因此,当用户输入一定量的点时,应用程序应找到输入的整数并显示正确的等级。到目前为止我的代码,我想我需要减去输入的整数,但我无法让它正常工作。任何帮助,将不胜感激。谢谢!
Public Class frmMain
Structure GradeCalculation
Public intPoint As Integer
Public strGrade As String
End Structure
Private arrGradeList(4) As GradeCalculation
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtPoints_Enter(sender As Object, e As EventArgs) Handles txtPoints.Enter
txtPoints.SelectAll()
End Sub
Private Sub txtPoints_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPoints.KeyPress
' allows only numbers and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub txtPoints_TextChanged(sender As Object, e As EventArgs) Handles txtPoints.TextChanged
lblGrade.Text = String.Empty
End Sub
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Dim intPointInput As Integer
Dim intSub As Integer
Integer.TryParse(txtPoints.Text, intPointInput)
Do Until intSub = arrGradeList.Length OrElse
intPointInput = arrGradeList(intSub).intPoint
intSub += 1
Loop
If intPointInput < arrGradeList.Length Then
lblGrade.Text = arrGradeList(intSub).strGrade
End If
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
arrGradeList(0).intPoint = 0
arrGradeList(0).strGrade = "F"
arrGradeList(1).intPoint = 300
arrGradeList(1).strGrade = "D"
arrGradeList(2).intPoint = 350
arrGradeList(2).strGrade = "C"
arrGradeList(3).intPoint = 420
arrGradeList(3).strGrade = "B"
arrGradeList(4).intPoint = 470
arrGradeList(4).strGrade = "A"
End Sub
答案 0 :(得分:-1)
Dim intPointInput As Integer = CInt(txtPoints.Text)
For Each grade As GradeCalculation In arrGradeList
If intPointInput >= grade.intPoint Then
lblGrade.Text = grade.strGrade
End If
Next