Home > Visual Basic 6 > TextBox Hanya Menerima Input Angka

TextBox Hanya Menerima Input Angka

Source code berikut untuk memfungsikan agar textbox hanya menerima input angka. Cocok digunakan untuk input kode pos atau no telepon.

Yang diperlukan :
1 Form
1 TextBox

Source code :

Public Sub HanyaAngka(ByRef KeyAscii As Integer)
    If ((KeyAscii < 48 And KeyAscii <> 8 ) Or KeyAscii > 57) Then
        KeyAscii = 0
    End If
End Sub

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

Download Source Code

  1. ce_amatiran
    February 13, 2011 at 12:03 pm

    kalo hanya emnerima angka dan koma..
    kira2 gimana yaa??
    ~.~

    • February 13, 2011 at 8:11 pm

      tambahin aja, keyascii untuk koma = 188 ,keyascii untuk titik = 190

  2. dev
    April 6, 2011 at 10:27 pm

    Makasi banget gan.. Sangat membantu dalam pembuatan tugas aku

  3. achmad
    July 10, 2011 at 10:19 am

    thanx ya….

  4. July 13, 2011 at 10:31 am

    klo mw input jam aja gimana

  5. November 8, 2011 at 10:15 pm

    maaf pak, untuk tambahin aja, keyascii untuk koma = 188 ,keyascii untuk titik = 190
    itu di letakan di sebelah mana dari coding yang diatas?

    1 Public Sub HanyaAngka(ByRef KeyAscii As Integer)
    2 If ((KeyAscii < 48 And KeyAscii 8 ) Or KeyAscii > 57) Then
    3 KeyAscii = 0
    4 End If
    5 End Sub
    6
    7 Private Sub Text1_KeyPress(KeyAscii As Integer)
    8 HanyaAngka KeyAscii
    9 End Sub

    Trimakasih pak

  6. hendry
    December 27, 2011 at 1:31 pm

    kok di visual studio 2010 ga jalan ya ??thx

    • December 27, 2011 at 8:07 pm

      itu untuk VB 6

      ________________________________

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: