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 :

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

Download Source Code

Read more...

TextBox Hanya Menerima Input Huruf

Source code berikut untuk memfungsikan textbox hanya bisa menerima input huruf. Bisa digunakan untuk input nama atau yang lainnya yang tidak menggunakan angka.

Yang diperlukan :
1 Form
1 TextBox

Source code pada Form :

1Public Sub HanyaHuruf(ByRef KeyAscii As Integer)
2 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
3 KeyAscii = 0
4 End If
5End Sub
6
7Private Sub Text1_KeyPress(KeyAscii As Integer)
8 HanyaHuruf KeyAscii
9End Sub

Download Source Code

Read more...

Koneksi Database Access Dengan Visual Basic 6

Source code berikut untuk mengoneksikan VB 6 dengan database Access. Agar aplikasi bisa di running dimana saja, dengan menggunakan fungsi App.Path, dan database Access disimpan dalam satu folder yang sama dengan project VB nya.

Source code simpan di Module :

01Public Conn As New ADODB.Connection
02
03Public Sub koneksi()
04On Error GoTo konekErr
05
06If Conn.State = 1 Then Conn.Close
07
08'sesuaikan database .mdb nya dengan database anda
09Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\db_tes.mdb;Persist Security Info=False"
10Exit Sub
11
12konekErr:
13 MsgBox "Gagal menghubungkan ke Database ! Kesalahan pada : " & Err.Description, vbCritical, "Peringatan"
14End Sub

Untuk penggunaannya dengan Adodc dan DataGrid, seperti contoh berikut :

1Private Sub Form_Load()
2koneksi 'pemanggilan koneksi database
3
4Adodc1.ConnectionString = Conn.ConnectionString
5Adodc1.RecordSource = "select * from contoh"
6Adodc1.Refresh
7Set DataGrid1.DataSource = Adodc1
8End Sub

Untuk lebih jelasnya, [Download Source Code]

Read more...