刚开始编程。大概3个月就到了。想知道这段代码有什么问题。 axwindow.url是当前正在播放的歌曲,因此它会根据哪首歌曲提出不同的问题。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Hide()
TextBox2.Hide()
TextBox3.Hide()
Label3.Text = "0"
username = InputBox("What is your name?")
Label2.Text = username + after
If Form1.AxWindowsMediaPlayer1.URL = champs Then
Label1.Text = "Who is the song We are the Champions by?"
TextBox1.Show()
End If
If Form1.AxWindowsMediaPlayer1.URL = rag Then
Label1.Text = "Who is the song Maple Leaf Rag by?"
TextBox2.Show()
End If
If Form1.AxWindowsMediaPlayer1.URL = pianoman Then
Label1.Text = "Who is the song Piano Man by?"
TextBox3.Show()
End If
Button1.Hide()
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If Form1.AxWindowsMediaPlayer1.URL = champs And TextBox1.Text = "Queen" Then
TextBox1.Text = "Correct!"
CheckBox1.Hide()
Button1.Show()
Else
TextBox1.Text = "Worng answer"
CheckBox1.CheckState = False
End If
If Form1.AxWindowsMediaPlayer1.URL = rag And TextBox2.Text = "Scott Joplin" Then
TextBox2.Text = "Correct!"
CheckBox1.Hide()
Button1.Show()
Else
TextBox2.Text = "Worng answer"
CheckBox1.CheckState = False
End If
If Form1.AxWindowsMediaPlayer1.URL = pianoman And TextBox3.Text = "Billy Joel" Then
TextBox3.Text = "Correct!"
CheckBox1.Hide()
Button1.Show()
Else
TextBox3.Text = "Worng answer"
CheckBox1.CheckState = False
End If
If TextBox1.Text <> "Queen" Or TextBox1.Text <> "Scott Joplin" Or TextBox1.Text <> "Billy Joel" Then
TextBox1.Text = "Wrong answer"
CheckBox1.CheckState = False
Else
TextBox1.Text = "Correct!"
End If
End Sub
出于某种原因,当我在文本框中写出斯科特乔普林时,它说正确并显示按钮一,但当我放下女王或比利乔尔的另外两个问题时,它说出了错误的答案,但仍然隐藏了复选框并显示了按钮。 / p>
非常感谢任何帮助!
答案 0 :(得分:0)
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If Form1.AxWindowsMediaPlayer1.URL = champs And TextBox1.Text = "Queen" Then
TextBox1.Text = "Correct!"
CheckBox1.Hide()
Button1.Show()
Exit Sub
Else
TextBox1.Text = "Worng answer"
CheckBox1.CheckState = False
Exit Sub
End If
If Form1.AxWindowsMediaPlayer1.URL = rag And TextBox2.Text = "Scott Joplin" Then
TextBox2.Text = "Correct!"
CheckBox1.Hide()
Button1.Show()
Exit Sub
Else
TextBox2.Text = "Worng answer"
CheckBox1.CheckState = False
Exit Sub
End If
If Form1.AxWindowsMediaPlayer1.URL = pianoman And TextBox3.Text = "Billy Joel" Then
TextBox3.Text = "Correct!"
CheckBox1.Hide()
Button1.Show()
Exit Sub
Else
TextBox3.Text = "Worng answer"
CheckBox1.CheckState = False
Exit Sub
End If
If TextBox1.Text <> "Queen" Or TextBox1.Text <> "Scott Joplin" Or TextBox1.Text <> "Billy Joel" Then
TextBox1.Text = "Wrong answer"
CheckBox1.CheckState = False
Exit Sub
Else
TextBox1.Text = "Correct!"
Exit Sub
End If
End Sub
尝试在每个条件下放置Exit Sub,以便其他“IF”条件不会被执行...
答案 1 :(得分:0)
好的我弄清楚我做错了什么。当我运行该程序时,它是逐行运行的,所以即使我没有尝试回答女王的问题,它还是会在其他任何事情发生之前立即转向其他问题。谢谢你告诉我断点非常有用。
,Nate