查看完整版本: TextBox 判斷空值問題
頁: [1]

u87cl3su3 發表於 2013-10-20 12:34 AM

TextBox 判斷空值問題

VB2012
請問 TextBox 可否再按下Button時 藉由Button按鍵 判斷它是否為空值?
判斷條件該怎麼下.....試了很久但不成功

另外 在判斷TextBox 之後 ,Button_Click 還有其他功能
但如果為空值我該怎麼讓程式停在判斷完之後

也試了很久,但程式一直往下跑  
<div></div>

darkjack 發表於 2013-10-20 06:07 PM

判斷空值 有兩種

字串if textbox1.text = "" then
'這邊就輸入你要執行的
end if二
任何數值if textbox1.text = nothting then
end if至於你說要停在你輸入空值的地方就像我上面寫的那種方式

u87cl3su3 發表於 2013-10-23 09:32 AM

OK  謝謝幫助  
愛你  啾咪  哈哈{:55:}

Jeepluo 發表於 2013-10-28 03:46 PM

空值的判斷有後多種,因為有時候輸入的是個空白字元,看來沒有但其實有的
可用字元長度做判斷
當字元長度為零時表示沒有輸入,否則就是有

roykinglo 發表於 2013-10-29 02:44 PM

VB.NET
String.IsNullOrEmpty(TextBox1.Text)
表示指定的字串是否為 null 或 Empty 字串。
<br><br><br><br><br><div></div>

roykinglo 發表於 2013-10-29 02:45 PM

本帖最後由 roykinglo 於 2013-10-29 10:28 PM 編輯

Class Sample
   Public Shared Sub Main()
      Dim s1 As String = "abcd"
      Dim s2 As String = ""
      Dim s3 As String = Nothing

      Console.WriteLine("String s1 {0}.", Test(s1))
      Console.WriteLine("String s2 {0}.", Test(s2))
      Console.WriteLine("String s3 {0}.", Test(s3))
   End Sub

   Public Shared Function Test(s As String) As String
      If String.IsNullOrEmpty(s) Then
         Return "is null or empty"
      Else
         Return String.Format("(""{0}"") is neither null nor empty", s)
      End If
   End Function
End Class  
' The example displays the following output:
'       String s1 ("abcd") is neither null nor empty.
'       String s2 is null or empty.
'       String s3 is null or empty....<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div>

swc1234 發表於 2014-7-13 11:08 AM

頁: [1]