vb中的一个程序,,,帮忙解决一下,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/22 15:07:24
Private Sub Command1_Click()
If Option1.Value = True Then
If Check1.Value = 1 Then
Text1.Text = "喜欢数学"
ElseIf Check2.Value = 1 Then
Text1.Text = "喜欢英语"
ElseIf Check1.Value = 1 And Check2.Value = 1 Then
Text1.Text = "喜欢数学英语"
End If
End If
If Option2.Value = True Then
If Check1.Value = 1 Then
Text1.Text = "不喜欢数学"
ElseIf Check2.Value = 1 Then
Text1.Text = "不喜欢英语"
Else
Text1.Text = "不喜欢数学英语"
End If
End If
End Sub

这个程序最后面的喜欢数学英语实现不了,我点击按钮就是没有正确的结果,,,高手解答一下,还有就是有没有更好的解决方法,,谢谢

if...then A
elseif...then B
else C
结构中,从上往下,只执行其中的一个就退出了,比如满足执行B的条件,就执行B,下面C就不执行了;
你的程序里,Check1.Value = 1 和Check2.Value = 1 中只要有一个成立,则执行上面两个分支了,并退出分支结构
可以这样改:
Private Sub Command1_Click()
If Option1.Value = True Then

If Check1.Value = 1 And Check2.Value = 1 Then
Text1.Text = "喜欢数学英语"
ElseIf Check2.Value = 1 Then
Text1.Text = "喜欢英语"
Else
Text1.Text = "喜欢数学"
End If

End If

If Option2.Value = True Then
If Check1.Value = 1 Then
Text1.Text = "不喜欢数学"
ElseIf Check2.Value = 1 Then
Text1.Text = "不喜欢英语"
Else
Text1.Text = "不喜欢数学英语"
End If
End If
End Sub