我是编程中的总菜鸟,但我真的需要帮助 无论如何,我必须在学校做一个10个问题的程序,当它们都是核心时它总是像5/10那样错了,但这里是代码
Public Class Form1
Dim score As Integer = 0
Dim varname As String
Private Sub cmdsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsubmit.Click
varname = txtname.Text
If txtbox1.Text = 18 Then
score = score + 1
End If
If txtbox1.Text <= 18 Then
score = score - 1
End If
If txtbox1.Text >= 18 Then
score = score + 0
End If
If txtbox2.Text = 10 Then
score = score + 1
End If
If txtbox2.Text <= 10 Then
score = score + 0
End If
If txtbox2.Text >= 10 Then
score = score + 0
End If
If rb11.Checked = True Then
score = score + 1
End If
If rb2q3.Checked = True Then
score = score + 0
End If
If cmboxq4.Text = "windows xp" Then
score = score + 1
End If
If rbq5.Checked = True Then
score = score + 1
End If
If score = 0 Then
MsgBox("you have scored 0 out of 10" & varname)
End If
If score = 1 Then
MsgBox("you have scored 1 out of 10 " & varname)
End If
If score = 2 Then
MsgBox("you have scored 2 out of 10" & varname)
End If
If score = 3 Then
MsgBox("you have scored 3 out of 10" & varname)
End If
If score = 4 Then
MsgBox("you have scored 4 out of 10" & varname)
End If
If score = 5 Then
MsgBox("you have scored 5 out of 10" & varname)
End If
If score = 6 Then
MsgBox("you have scored 6 out of 10" & varname)
If score = 7 Then
MsgBox("you have scored 7 out of 10" & varname)
If score = 8 Then
MsgBox("you have scored 8 out of 10" & varname)
If score = 9 Then
MsgBox("you have scored 9 out of 10" & varname)
End If
End If
End If
End If
End Sub
结束班
答案 0 :(得分:0)
尝试使用以下代码替换“if score”语句:
Select Case score
Case 0
MsgBox("you have scored 0 out of 10" & varname)
Case 1
MsgBox("you have scored 1 out of 10" & varname)
Case 2
MsgBox("you have scored 2 out of 10" & varname)
Case 3
MsgBox("you have scored 3 out of 10" & varname)
Case 4
MsgBox("you have scored 4 out of 10" & varname)
Case 5
MsgBox("you have scored 5 out of 10" & varname)
Case 6
MsgBox("you have scored 6 out of 10" & varname)
Case 7
MsgBox("you have scored 7 out of 10" & varname)
Case 8
MsgBox("you have scored 8 out of 10" & varname)
Case 9
MsgBox("you have scored 9 out of 10" & varname)
Case 10
MsgBox("you have scored 10 out of 10" & varname)
End Select
答案 1 :(得分:0)
你的比较(起初至少)毫无意义。
你去= 18,&lt; = 18,&gt; = 18
如果值为18,则忽略前两个比较,重复该错误以与10进行比较。
如果不知道你想要做什么,我会说他们应该这样做 = 18,&lt; 18,&gt; 18