Anto's Blog

Validasi Program dengan menggunakan Visual Basic 6.0






Kumpulan Source Code tuk Validasi Program dengan menggunakan Visual Basic 6.o, Jika anda tertatik dengan Tips dan Trik Visual Basic ini Silahkan Baca.


  • Hanya Angka yang bisa di Input dalam TextBoxt 

Private Sub txtNomor_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") & Chr(13) _
And KeyAscii <= Asc("9") & Chr(13) _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyDelete _
Or KeyAscii = vbKeySpace) Then
Beep
KeyAscii = 0
End If
End Sub





  • Hanya Huruf yang bisa di Input dalam TextBoxt 
Private Sub txtNama_KeyPress(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
Beep
KeyAscii = 0

End If

End Sub
  • Membersihkan Seluruh Control TextBox dan Combo Box 
Sub Clear()

For Each Control In Me.Controls
If TypeOf Control Is TextBox Then
Control.Text = ""
End If
If TypeOf Control Is ComboBox Then
Control.Text = ""
End If
Next Control
End Sub
NB: jika ada tombol yang lain tinggal di tambah kondisi IFnya aja, dan tuk menonaktifkan seluruh tombol tinggal ganti "Control.Text="" Menjadi Control.Enabled=false" aja. Semoga Bermanfa'at.






No comments

Isilah komentar disini...

Powered by Blogger.