作者j76992001 (人缘有待等)
看板Visual_Basic
标题[VB2008]一个TextBox的问题
时间Sat Apr 11 09:03:30 2009
Public Class Form1
Dim x, y, z
Dim sum As Integer
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If MsgBox("确定离开程式", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "离开程式") = MsgBoxResult.Yes Then
End
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
x = Val(TextBox1.Text)
If x < 0 Or x > 1000 Then
MsgBox("数值输入错误", , "警告")
TextBox1.Text = Nothing
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If x = Nothing Or x < 0 Or x>1000 Then
MsgBox("还没输入喔", , "警告")
TextBox1.Text = Nothing
Else
Label2.Text = Label2.Text + 1
Label5.Text = Label5.Text + 1
Label8.Text = Label8.Text + x
TextBox1.Text = Nothing
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
End Sub
End Class
这是一个输入数值然後执行累加的程式,在输入数值的TextBox1_TextChanged事件中,
我设定条件必须输入数值才能执行累加的动作,但是假设我输入的是数值为"0",
却还是进到例外的范围内.我有试过把x = Nothing拿掉,这样虽然可以让0累加成功,
却会发生不输入数值也能执行累加的问题... 想请问一下有什麽办法可以解决这样的问题
--
曾经沧海难为水~~
~~ 除却巫山不是云
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.118.70.69