我写了一些代码,根据原始分数是小于50还是大于50,在测试分数上增加了一定数量的分数。一切正常,除非数字接近或小于50。例如,如果数字小于50,我在分数上加7,如果数字大于50,则我给分数加4,数字是49,它将7和4而不是仅仅加7。我想要什么?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'declare variables
Dim scores(5) As Integer 'array of 6 variables named scores with inded values of 0-6
Dim i As Integer
Dim add1 As Integer
Dim add2 As Integer
For i = 0 To scores.Length - 1
scores(i) = Val(InputBox("Input six scores:", "Enter Scores"))
Next i
add1 = Val(Me.txtBelow.Text)
add2 = Val(Me.txtAbove.Text)
For i = 0 To scores.Length - 1
If scores(i) < 50 Then
scores(i) = scores(i) + add1
End If
If scores(i) > 50 Then
scores(i) = scores(i) + add2
End If
Next i
For i = 0 To scores.Length - 1
Me.lblOutput.Text = Me.lblOutput.Text & scores(i) & " "
Next i
答案 0 :(得分:0)
使用ElseIf
语法。
Private Function CheckIfTime() As Boolean
' Determine the current day of week and hour of day.
Dim dayW As DayOfWeek = DateTime.Now.DayOfWeek
Dim hour As Integer = DateTime.Now.Hour
' Return True if Wednesday from 2 to 3:59 P.M.,
' or if Thursday from noon to 12:59 P.M.
If dayW = DayOfWeek.Wednesday Then
If hour = 14 Or hour = 15 Then
Return True
Else
Return False
End If
ElseIf dayW = DayOfWeek.Thursday Then
If hour = 12 Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function