Jumat, 12 Agustus 2011

Hanya huruf besar, hanya huruf, dan hanya angka yang ditampilkan di texbox

Berikut contoh-contoh untuk mengubah inputan ke textbox menjadi huruf besar :
contoh 1 :
Private Sub Text2_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
Contoh 2 :
Public Function CapitalLetter(objectToIgnore As TextBox)
    objectToIgnore.Text = UCase(objectToIgnore.Text)
    objectToIgnore.SelStart = Len(objectToIgnore)
End Function

Private Sub Text1_Change(Index As Integer)
    Select Case Index
    Case 0
        objects = CapitalLetter(Text1(0))
    Case 1
        objects = CapitalLetter(Text1(1))
    End Select
End Sub


Berikut contoh hanya angka yang boleh diinput:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'hanya dapat diisi angka 0 - 9
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then KeyAscii = 0
End Sub
Berikut contoh hanya huruf yang boleh diinput:
Public Sub Huruf(ByRef KeyAscii As Integer)
    If Not (KeyAscii >= Asc("a") & Chr(13) And KeyAscii <= Asc("z") & Chr(13) Or (KeyAscii >= Asc("A") & Chr(13) And KeyAscii <= Asc("Z") & Chr(13) Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeySpace)) Then
        KeyAscii = 0
    End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Huruf KeyAscii
End Sub

0 komentar:

Posting Komentar

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Justin Bieber, Gold Price in India