老实说,我不知道自己做错了什么。我有一个名为“txtNumSticks”的文本框,用户输入一个数字。用户点击开始后,我想要弹出一个消息框,上面写着“好吧!我们会玩(x)棒!”但我无法让它发挥作用。第一天学习VB.net。提前致谢!
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
Dim NumSticks As String
txtNumSticks.Text = NumSticks
Game.Show()
Me.Close()
MessageBox.Show("Okay! We'll play with " & NumSticks & "sticks!")
End Sub
答案 0 :(得分:4)
您正在以错误的方式设置变量,应该将NumSticks分配给文本框中的值,以便:
NumSticks = txtNumSticks.Text
或者不使用变量
MessageBox.Show("Okay! We'll play with " & txtNumSticks.Text & "sticks!")
答案 1 :(得分:2)
您可能需要在程序中添加一些错误检查,以确保输入的值为数字。
Dim NumSticks As String
NumSticks = txtNumSticks.Text.ToString
If IsNumeric(NumSticks) Then
Game.Show()
MessageBox.Show("Okay! We'll play with " & NumSticks & " sticks!")
Me.Close()
Else
' Let user know the value is non-numeric
MessageBox.Show("Non Numeric Value entered", "Error!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If