Wednesday, August 15, 2012

Membuat TextBox Hanya Menerima Input Huruf/Angka di Visual Basic 6.0 (VB)

 __________________Huruf_________________
Public Sub Huruf(ByRef KeyAscii As Integer)
   If Not (KeyAscii >= Asc("1") & Chr(13) And KeyAscii <= Asc("a") & Chr(13) Or (KeyAscii >= Asc("Z") & Chr(13) And KeyAscii <= Asc("Z") & Chr(13) Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeySpace)) Then
        KeyAscii = 0
    End If
End Sub
Pemakaian :
Private Sub Text1_KeyPress(KeyAscii As Integer)
    Huruf KeyAscii
 End Sub


__________________Angka________________
Public Sub Huruf(ByRef KeyAscii As Integer)
   If Not (KeyAscii >= Asc("1") & Chr(13) And KeyAscii <= Asc("1") & Chr(13) Or (KeyAscii >= Asc("0") & Chr(13) And KeyAscii <= Asc("Z") & Chr(13) Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeySpace)) Then
        KeyAscii = 0
    End If
End Sub
Pemakaian :
Private Sub Text1_KeyPress(KeyAscii As Integer)
   Huruf KeyAscii
 End Sub

0 comments:

Post a Comment