Batasan Keyboard Dalam Visual Basic 6.0
Batasan keyboard ini yaitu jika dalam
program hanya ingin menginputkan data dari keyboard berupa angka saja, berupa
huruf saja, angka dan huruf, atau simbol saja. Coding untuk membuat keadaan
seperti itu yaitu di general tulis coding Option Explicit kemudian
masuk ke coding pembatasan :
1. Hanya Angka ( Text1 dengan event
keypress)
If Not (Chr(KeyAscii) Like "[0-9]" _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyReturn _
Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
End If
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyReturn _
Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
End If
2. Hanya Huruf (Text2 dengan event keypress)
If Not (Chr(KeyAscii) Like "[A-Za-z]" _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyReturn _
Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
End If
If Not (Chr(KeyAscii) Like "[A-Za-z]" _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyReturn _
Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
End If
3. Hanya Angka dan Huruf (Text3 dengan event keypress)
If Not (Chr(KeyAscii) Like "[A-Za-z0-9]" _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyReturn _
Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
4. Hanya Simbol (Text4 dengan event keypress)
If (Chr(KeyAscii) Like "[A-Za-z0-9]" _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyReturn _
Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
End If
If (Chr(KeyAscii) Like "[A-Za-z0-9]" _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyReturn _
Or KeyAscii = vbKeyDelete) Then
KeyAscii = 0
End If
Labels: Pemrograman, Visual Basic 6.0
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home