看板 Visual_Basic 關於我們 聯絡資訊
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 = "" End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "" Or x < 0 Or x > 1000 Then MsgBox("還沒輸入喔", , "警告") TextBox1.Text = "" Else Label2.Text = Val(Label2.Text) + 1 Label5.Text = Val(Label5.Text) + 1 Label8.Text = Val(Label8.Text) + x TextBox1.Text = "" End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = "" End Sub End Class 做了小幅修改 應該可以正常執行 1.把nothing改成"" 2.判斷的地方把x=nothing改成textbox1.text="" 3.Button2_click的地方改成textbox1.text="" 4.把button1_click那邊label的地方加上val() -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.162.36
j76992001:請問Nothing改為"", ""代表的意思是...?? 不嫌麻煩請跟 04/11 13:19
j76992001:我講解一下~"~ 還有 第4個項目我保留我原本的樣子,運算 04/11 13:20
j76992001:結果還是可以,是因為前後都是數值的關係嗎?所以"+"變成 04/11 13:20
j76992001:數值運算子,是這樣子嗎? 04/11 13:21
j76992001:也感謝Y大的熱心回答^^ 04/11 13:23
Y78:""代表的就是空字串,例如說你想要把TextBox1的Text變成空白 04/11 22:11
Y78:就用TextBox1.Text = "" 就會變成空白了 04/11 22:11
Y78:至於你用的Nothing,抱歉 我沒用過 所以也不太知道功用 04/11 22:12
Y78:至於數值那邊 如果把Val()去掉 我這邊的執行結果會錯誤 04/11 22:12
Y78:因為 Label2.Text得到的值不管Label2的內容是2還是"2" 04/11 22:13
Y78:都會回傳一個字串"2" (我記得是這樣) 所以要加上Val轉成數值 04/11 22:13
Peruheru:應該是反過來說,Label2的Text屬性就是字串類型 04/11 23:34
Peruheru:所以不管你給他值或是跟他要值,都是字串 04/11 23:34
Peruheru:只是給它值時,他會幫你轉換成字串 04/11 23:35
Peruheru:Nothing好像指的是一切物件的初始值 04/11 23:35
Peruheru:或者是說,沒有內容的物件,其內容就等於Nothing 04/11 23:36
Peruheru:但是空字串並不等於Nothing,空字串就是"" 04/11 23:36