0
我有VB程序,用戶是使用InputBox輸入成績。無論用戶輸入什麼,都會顯示一個消息框(msgbox),指出「請輸入一個數字」。如果沒有輸入號碼,我該如何改變它才顯示這條信息?VB迷惑了,如果路徑
Option Strict Off
Public Class Form1
Dim totalpointsaccumultator As Object
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Public Sub assignButton_Click(sender As Object, e As EventArgs) Handles assignButton.Click
Dim inputProjectPoints, inputTestPoints As String
Dim grade, projectpoints, testpoints As String
Dim projectcounter As Integer = 1
Dim testcounter As Integer = 1
Dim isconverted As Boolean
Dim totalpointsaccumulator As Integer
Do While projectcounter < 5
inputProjectPoints = InputBox("Enter the points earned on project " & projectcounter, "Grade Calculator", "0")
inputProjectPoints = projectpoints
isconverted = Integer.TryParse(inputProjectPoints, CInt(projectpoints))
If isconverted Then
totalpointsaccumultator = totalpointsaccumulator + projectpoints
projectcounter = projectcounter + 1
Else
MessageBox.Show("Please enter a number.", "Grade Calculator", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Loop
Do While testcounter < 3
inputTestPoints = InputBox("Enter the points earned on test " & testcounter, "Grade Calculator", "0")
isconverted = Integer.TryParse(inputTestPoints, testpoints)
If isconverted Then
testcounter = testcounter + 1
totalpointsaccumulator = CInt(totalpointsaccumulator + testpoints)
Else
MessageBox.Show("Please enter a number.", "Grade calculator", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Loop
' assign grade
Select Case totalpointsaccumulator
Case Is >= 360
grade = "A"
Case Is >= 320
grade = "B"
Case Is >= 280
grade = "C"
Case Is >= 240
grade = "D"
Case Else
grade = "F"
End Select
totalpointsLabel.Text = Convert.ToString(totalpointsaccumulator)
gradeLabel.Text = grade
End Sub
End Class
我會簡化代碼,然後在這裏呈現仍然產生錯誤的最小可能版本。這不是最小的可能版本。機會很高,你會發現自己的錯誤或來自這裏的人會發現它更快。 – Trilarion
看起來像你在這裏覆蓋你的輸入:「inputProjectPoints = projectpoints」 –
Turn Option Strict ON not off! – Plutonix