Re: [VB2008]一個TextBox的問題

看板Visual_Basic作者 (Y78)時間16年前 (2009/04/11 11:30), 編輯推噓2(2015)
留言17則, 3人參與, 最新討論串2/2 (看更多)
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

04/11 13:19, , 1F
請問Nothing改為"", ""代表的意思是...?? 不嫌麻煩請跟
04/11 13:19, 1F

04/11 13:20, , 2F
我講解一下~"~ 還有 第4個項目我保留我原本的樣子,運算
04/11 13:20, 2F

04/11 13:20, , 3F
結果還是可以,是因為前後都是數值的關係嗎?所以"+"變成
04/11 13:20, 3F

04/11 13:21, , 4F
數值運算子,是這樣子嗎?
04/11 13:21, 4F

04/11 13:23, , 5F
也感謝Y大的熱心回答^^
04/11 13:23, 5F

04/11 22:11, , 6F
""代表的就是空字串,例如說你想要把TextBox1的Text變成空白
04/11 22:11, 6F

04/11 22:11, , 7F
就用TextBox1.Text = "" 就會變成空白了
04/11 22:11, 7F

04/11 22:12, , 8F
至於你用的Nothing,抱歉 我沒用過 所以也不太知道功用
04/11 22:12, 8F

04/11 22:12, , 9F
至於數值那邊 如果把Val()去掉 我這邊的執行結果會錯誤
04/11 22:12, 9F

04/11 22:13, , 10F
因為 Label2.Text得到的值不管Label2的內容是2還是"2"
04/11 22:13, 10F

04/11 22:13, , 11F
都會回傳一個字串"2" (我記得是這樣) 所以要加上Val轉成數值
04/11 22:13, 11F

04/11 23:34, , 12F
應該是反過來說,Label2的Text屬性就是字串類型
04/11 23:34, 12F

04/11 23:34, , 13F
所以不管你給他值或是跟他要值,都是字串
04/11 23:34, 13F

04/11 23:35, , 14F
只是給它值時,他會幫你轉換成字串
04/11 23:35, 14F

04/11 23:35, , 15F
Nothing好像指的是一切物件的初始值
04/11 23:35, 15F

04/11 23:36, , 16F
或者是說,沒有內容的物件,其內容就等於Nothing
04/11 23:36, 16F

04/11 23:36, , 17F
但是空字串並不等於Nothing,空字串就是""
04/11 23:36, 17F
文章代碼(AID): #19u0x4Dp (Visual_Basic)
文章代碼(AID): #19u0x4Dp (Visual_Basic)