Variasi dikit dari saya: :D
   
  Public Function ValidInput(KeyAscii As Integer) As Boolean
    Select Case KeyAscii
        Case Asc("0") To Asc("9"), _
             Asc("A") To Asc("Z"), _
             Asc("a") To Asc("z"), vbKeyBack, vbKeyDelete
            ValidInput = True
        Case Else
            ValidInput = False
    End Select
End Function
   
  Private Sub Text1_KeyPress(KeyAscii As Integer)
    If Not ValidInput(KeyAscii) Then KeyAscii = 0
End Sub

Lilis <[EMAIL PROTECTED]> wrote:
          hallo programmer

sedikit trik nih utk membuat validasi inputan, contoh ini biasanya dibuat 
spy user ga salah menginput.

ketik kodingnya spt dibawah ini pada event keypress

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Not KeyAscii >= Asc("A") Or Not KeyAscii <= Asc("Z")) _
And (Not KeyAscii >= Asc("0") Or Not KeyAscii <= Asc("9")) _
And KeyAscii <> Asc(vbBack) Then

MsgBox "Hanya huruf dan Angka aja"

End If
End Sub

kode diatas hnya membatasi user utk menginput huruf atau angka dan backspace 
utk menghapus kalo ada kesalahan
dan hurufnya nya pun cuma bisa huruf besar aja jadi perlu ditambah spy bisa 
juga utk huruf kecil dan juga mungkin
perlu ditambah spasi ( itu PR yg hrs diselesaikan ) dan kalo diperhatikan, 
aku menggunakan sintak Asc daripada Chr, kenapa?
karena kalo memakai chr kombinasinya kan dgn angka sehingga bacanya agak 
susah bagi orang awam spt aku.
tapi kalo menggunakan asc spt diatas, kodenya jadi jelas dan maksudnya dapat 
dimengerti.

ok semoga bermanfaat, sampe ketemu di trik berikutnya :-)

salam
lilis


  .

 
                         




Jemmy H. Tecoalu
Personal blog: 
  http://jemmyt.blogspot.com
  http://geeks.netindonesia.net/blogs/jemmy

"The present was affected by the past, and the present will affect the future."


       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.

Kirim email ke