Validasi dalam VB

  • Mengetahui Kode Ascii pada VB6

1. Tambahkan Form

2. Tambahkan textbox

3. Tuliskan source code sbb

Private Sub Form_Load()
Text1.Enabled = False

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Text1 = KeyAscii

End Sub

4. Jalankan Form lalu tekan tombol keyboard maka kode ascii akan tampil pada textbox (Text1)

  • Penggunaan Tombol F1 ~ F12

1. Tambahkan commandbutton pada form

atur properties, caption = F2

2. Klik Form ,lalu atur properties

Key Preview = True

3. Masukkan source code

Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF2 Then
msgbox “Berhasil”
End If
End Sub

4. Jalankan Form lalu tekan F2 maka akan muncul pesan “Berhasil”

  • Huruf Besar Pada Textbox


1. Tambahkan textbox pada form

2. kode

Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

  • Validasi Untuk angka


Biasanya dipakai untuk harga atau yang menggunakan angka saja.

Private Sub Text3_KeyPress(KeyAscii As Integer)
strangka = “0123456789”
If KeyAscii > 26 Then
If InStr(strangka, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
End Sub

  • UNTUK MENGETAHUI JUMLAH BARIS
SQL = “select count (kdbarang) as jum from DPO”
Set ress = hub.Execute(SQL, , adCmdText)
ro = ress!jum
MSFlexGrid1.Rows = ro + 1
—————————————-
With res
If Not .EOF Then
.MoveFirst
Do While Not .EOF
MSFlexGrid1.TextMatrix(bs, 0) = bs
MSFlexGrid1.TextMatrix(bs, 1) = !Kdbarang
  • MENAMPILKAN DATA QTY dan HARGA dan TOTAL HARGA
MSFlexGrid1.TextMatrix(bs, 3) = !qty
MSFlexGrid1.TextMatrix(bs, 4) = !harga
MSFlexGrid1.TextMatrix(bs, 5) = Val(!qty) * Val(!harga)
.MoveNext
bs = bs + 1
Loop
End If
End With
End Sub

2 comments on “Validasi dalam VB

Tinggalkan komentar