Welcome To _TORAJAIT_

0
Selamat Pagi Teman2 , Lama neh Tidak ngeposting iLmu tentang Komputer .
Kali ini So' Alen memposting ILmu Pemrograman , Bagi yang suka bermain dengan Visual Basic " VB " . Disini So' Alen Berbagi "MODUL TUTORIAL 
MICROSOFT VISUAL BASIC -  PROGRAM APLIKASI PENJUALAN "
*Berikut Ini Langakah2 dan Kodingnya Silahkan di Sedot ILmunya ....

1.Buka Aplikasi microsoft visual basic 
- Double klik pada icon di dektop atau klik start  all program  microsoft visual studio  microsoft visual basic
2.Pilih new project  standart EXE


3.Rancang/design form login seperti berikut
 
 
Single user :
Ketik listing program sebagi berikut
- Double klik pada form atau
- Pilih menu view  code


Private Sub CmdOk_Click()
If TxtUserName.Text = "admin" And Txtpassword.Text = “12345” Then
Me.Hide
Formmenu.Show
Formmenu.Enabled = True
Else
MsgBox "Anda Kemungkinan salah memasukkan Username atau password, Coba lagi....!", , "Login"
TxtUserName.Text = ""
Txtpassword.Text = ""
TxtUserName.SetFocus
End If
End Sub

Private Sub CmdCancel_Click()
a = MsgBox("Apakah anda ingin keluar?", vbQuestion + vbOKCancel, "Info")
If a = vbOK Then
End
End Sub

Private Sub Form_Activate()
TxtUserName.Text = ""
TxtUserName.SetFocus
End Sub

Private Sub Form_Load()
Formmenu.Show
Formmenu.Enabled = False
End Sub

Private Sub Txtpassword_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
CmdOk.SetFocus
End If
End Sub

Private Sub TxtUserName_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Txtpassword.SetFocus
End If
End Sub 
Lihat hasil (jalankan program)
- Tekan F5 pada keyboard atau 
- Menu run  start
Rancang form menu utama
- Pilih menu project  add form
Simpan dengan nama formmenu
- Pilih menu Tool  Menu editor 
- Isi caption dan name sesuai kebutuhan atau sbb


Hasil Design Form  


Buatlah tabel Barang /Buku
- Menu Add-Ins  Visual data manager
- Muncul kotak dialog visdata 
- pilih file  open database  microsoft access (untuk membuka database yang sudah ada)
- pilih file  new database  microsoft access  version 7.0 (untuk membuat database baru)
- klik kanan pada properties  pilih new tabel
isikan field2 nya sbb:

Setelah selesai klik buid the table


Buatlah form sbb berikut:


Source Code/ Listing Program

Sub bersih()
For Each X In Me
If TypeName(X) = "TextBox" Then
X.Text = ""
End If
Next
For Each X In Me
If TypeName(X) = "ComboBox" Then
X.Text = "Pilih ------------------------->"
End If
Next
End Sub
Sub tampil()
If Data1.Recordset.BOF Then
bersih
Else
txkode.Text = Data1.Recordset!kd_buku
txjdl.Text = Data1.Recordset!jdl_buku
cmbjns.Text = Data1.Recordset!jns_buku
txtpng.Text = Data1.Recordset!pengarang
txtterbit.Text = Data1.Recordset!penerbit
txtjml.Text = Data1.Recordset!jml_stok
txthrg.Text = Data1.Recordset!Harga
End If
End Sub

Sub nonaktif()
For Each X In Me
If TypeName(X) = "TextBox" Then
X.Enabled = False
End If
Next
For Each X In Me
If TypeName(X) = "ComboBox" Then
X.Enabled = False
End If
Next
cmdtambah.Enabled = True
cmdcari.Enabled = True
cmdkeluar.Enabled = True
cmdbatal.Enabled = False
cmdSimpan.Enabled = False
CmdHapus.Enabled = False
CmdUbah.Enabled = False
End Sub

Sub aktif()
For Each X In Me
If TypeName(X) = "TextBox" Then
X.Enabled = True
End If
Next
For Each X In Me
If TypeName(X) = "ComboBox" Then
X.Enabled = True
End If
Next

cmdtambah.Enabled = False
cmdcari.Enabled = False
cmdkeluar.Enabled = False
cmdbatal.Enabled = True
cmdSimpan.Enabled = True
End Sub

Private Sub cmbjns_Click()
txtpng.SetFocus
End Sub

Private Sub cmdbatal_Click()
Data1.Recordset.CancelUpdate
nonaktif
tampil
tampil
End Sub

Private Sub Cmdcari_Click()
a = InputBox("Masukan Kode Buku", "Pencarian")
Data1.Recordset.Index = "Kd_buku"
Data1.Recordset.Seek "=", a
If Not Data1.Recordset.NoMatch Then
tampil
CmdHapus.Enabled = True
CmdUbah.Enabled = True
cmdtambah.Enabled = False
cmdkeluar.Enabled = False
cmdcari.Enabled = False
Else
MsgBox "Kode Buku TIdak Ditemukan", , "Info Buku"
End If
End Sub

Private Sub cmdhapus_Click()
If Data1.Recordset.BOF Then
bersih
MsgBox "Data Kosong"
Else
Data1.Recordset.Delete
Data1.Recordset.MoveFirst
CmdHapus.Enabled = False
CmdUbah.Enabled = False
End If
tampil
nonaktif
End Sub
Private Sub cmdkeluar_Click()
    Unload Me
End Sub

Private Sub cmdSimpan_Click()
If txkode.Text = "" Or txjdl.Text = "" Or cmbjns.Text = "Pilih ------------------------->" Or txthrg.Text = "" Or txtterbit.Text = "" Or txtjml.Text = "" Then
MsgBox "Data Belum Lengkap", vbExclamation, "Peringatan"
txkode.SetFocus
Exit Sub
End If
Data1.Recordset!kd_buku = txkode.Text
Data1.Recordset!jdl_buku = txjdl.Text
Data1.Recordset!jns_buku = cmbjns.Text
Data1.Recordset!pengarang = txtpng.Text
Data1.Recordset!penerbit = txtterbit.Text
Data1.Recordset!jml_stok = txtjml.Text
Data1.Recordset!Harga = txthrg.Text
Data1.Recordset.Update
Data1.Refresh
nonaktif
tampil
End Sub

Private Sub cmdtambah_Click()
aktif
bersih
txkode.SetFocus
Data1.Recordset.AddNew
End Sub

Private Sub cmdubah_Click()
Data1.Recordset.Edit
CmdHapus.Enabled = False
CmdUbah.Enabled = False
aktif
txkode.Enabled = False
txjdl.SetFocus
End Sub

Private Sub DBGrid1_DblClick()
With DBGrid1
txkode = .Columns(0)
txjdl = .Columns(1)
txtpng = .Columns(2)
txtterbit = .Columns(3)
cmbjns = .Columns(4)
txtjml = .Columns(5)
txthrg = .Columns(6)
End With
tampil
End Sub

Private Sub DBGrid1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
With DBGrid1
txkode = .Columns(0)
txjdl = .Columns(1)
txtpng = .Columns(2)
txtterbit = .Columns(3)
cmbjns = .Columns(4)
txtjml = .Columns(5)
txthrg = .Columns(6)
End With
tampil
End If
End Sub
Private Sub Form_Activate()
nonaktif
tampil
cmdtambah.SetFocus
End Sub
Private Sub Form_Load()
Con
Data1.DatabaseName = App.Path + "\penjualan.mdb"
Data1.RecordSource = "buku"
End Sub


Private Sub txjdl_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmbjns.SetFocus
End If
End Sub

Private Sub txkode_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then
Data1.Recordset.Index = "kd_buku"
Data1.Recordset.Seek "=", txkode
If Not Data1.Recordset.NoMatch Then
MsgBox "Kode Buku Sudah Ada", vbCritical, "Info"
txkode.Text = ""
Else
txjdl.SetFocus
End If
Data1.Recordset.AddNew
End If
End Sub

Private Sub txthrg_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtjml.SetFocus
End If
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

Private Sub txtjml_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmdSimpan.SetFocus
End If
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

Private Sub txtpng_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtterbit.SetFocus
End If
End Sub

Private Sub txtterbit_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txthrg.SetFocus
End If
End Sub 

Demikainlah Langkah2 dan Koding Programnya Teman2 . Selamat Mencoba ya ...
Dan Jangan Pernah Lelah Berkunjung ke "www.torajait.com"
Terima Kasih ...

Post a Comment

 
Top