English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

有辦法讓TEXT物件裡面只能輸入數字跟英文嗎,讓使用者不能輸入任何符號跟中文字,煩請各位大大幫我解答,謝謝~

2006-05-26 20:52:38 · 4 個解答 · 發問者 hothero 4 in 電腦與網際網路 程式設計

關於vb6.0的~下面的大大~你的方法不但不能用backspace而且我輸入中文字還是一樣沒問題耶...

2006-05-27 17:15:38 · update #1

4 個解答

我用的是VB.NET

這是只能輸入英文
If (e.KeyChar < "a" Or e.KeyChar > "z") And e.KeyChar <> vbBack Then
e.Handled = True
End If

這是只能輸入數字
If (e.KeyChar < "0" Or e.KeyChar > "9") And e.KeyChar <> vbBack Then
e.Handled = True
End If

這是只能輸入英文和數字
If (e.KeyChar < "0" Or e.KeyChar > "9") And (e.KeyChar <= "z" Or e.KeyChar >= "a") And e.KeyChar <> vbBack Then
e.Handled = True
End If

2006-05-27 17:30:00 補充:
要寫在TEXT_KeyPress裡面才可以

2006-05-30 15:30:08 補充:
不好意思 上面有一個地方打錯了
只能輸入英文和數字的程式碼如下↓
If (e.KeyChar < "0" Or e.KeyChar > "9") And (e.KeyChar < "a" Or e.KeyChar > "z") And e.KeyChar <> vbBack Then
e.Handled = True
End If

2006-05-30 15:31:20 補充:
原來是vb6.0的~這個方法是.net才能用
抱歉呢沒幫上忙

2006-05-27 13:28:48 · answer #1 · answered by ? 2 · 0 0

Private Sub Text1_KeyPress(KeyAscii As Integer)        Dim S$                S = "0123456789" & Chr(8) & Chr(13)        For I = 65 To 90            S = S & Chr(I)        Next        If InStr(1, S, Chr(KeyAscii), vbTextCompare) = 0 Then KeyAscii = 0End Sub

2006-05-29 09:49:18 · answer #2 · answered by W.J.S. 7 · 0 0

利用Text1_KeyPress中的KeyAscii來判斷
程式碼在下面,不過不能用BACKSPACE
你自己可以改一下
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 0 To 47
KeyAscii = 0
Exit Sub
Case 58 To 64
KeyAscii = 0
Exit Sub
Case 91 To 96
KeyAscii = 0
Exit Sub
Case 123 To 255
KeyAscii = 0
Exit Sub
End Select
End Sub

2006-05-26 23:10:48 · answer #3 · answered by puppy 5 · 0 0

VB6 or VB.Net?

2006-05-26 22:05:25 · answer #4 · answered by Luke 4 · 0 0

fedest.com, questions and answers