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