P. 1
Diktat Visual Basic 1 2009

Diktat Visual Basic 1 2009

4.25

|Views: 9,029|Likes:
Dipublikasikan oleh hendrik_hutabarat6234

More info:

Published by: hendrik_hutabarat6234 on Aug 02, 2009
Hak Cipta:Traditional Copyright: All rights reserved

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC or read online from Scribd
See more
See less

05/09/2015

113.

Pastikan kita berada didalam projek MenuUtamaDataNilai yang sudah
berisi Menu, Database dan tiga buah table. Kemudian klik menu Project+Add
Form

Microsoft Visual Basic 6.0

162

114.

Pastikan pilihan pada Tab New dan icon Form, lalu klik tombol Open.

OBJEK

PROPERTI

PENGATURAN

Form1

Caption

Form Data Nilai Siswa

Name

FrmDataNilaiSiswa

Height

3600

Left

0

Top

0

Width

5835

CommandButton1Caption

&Cetak ke Layar

Name

CmdCetakKeLayar

Height

495

Left

120

Top

360

Width

1575

CommandButton2Caption

Cetak ke &Printer

Name

CmdCetakKePrinter

Height

495

Left

2160

Top

360

Width

1695

CommandButton3Caption

&Tutup

Height

495

Microsoft Visual Basic 6.0

163

Left

4200

Top

360

Width

1215

Data1

Caption

Data Nilai
DatabaseNameE:\VB98\Databases
Nilai.mdb

RecordSource

TabelNilai

RecordsetType0-Table
Height

495

Left

240

Top

1200

Width

4455

Tambahkan Form2 dengan mengklik menu Project + Add Form, kemudian atur
propertinya sebagai berikut :

OBJEK

PROPERTI

PENGATURAN

Form2

Name

FrmCetakLayarNilai

Caption

Form Cetak Layar Nilai

Height

5670

Left

0

Top

0

Width

8475

115.

Klik ganda didalam Form yang tidak berisi object, maka akan tampil
jendela Code. Masukkan kode dibawah ini.

Private Sub CetakLayarNilai()
Dim msubtotal, mtotal As Long
Dim mno, mhal, mbaris As Integer
Dim mjumlah As Double
Dim mgrs As String
FrmCetakLayarNilai.Font = "Courier New"
Data1.Recordset.MoveFirst
mtotalharga = 0
mno = 0
Do While Not Data1.Recordset.EOF
FrmCetakLayarNilai.Print
FrmCetakLayarNilai.Print
FrmCetakLayarNilai.FontBold = True
FrmCetakLayarNilai.FontSize = 10
FrmCetakLayarNilai.Print Tab(10); "Data Nilai Siswa"
FrmCetakLayarNilai.Print Tab(10); "Tanggal Cetak :"; Format(Date, "DD-
MM-YYYY")
FrmCetakLayarNilai.FontBold = False
FrmCetakLayarNilai.Print
mgrs = String$(65, "-")
FrmCetakLayarNilai.Print Tab(1); mgrs
FrmCetakLayarNilai.Print Tab(1); "Nis";
FrmCetakLayarNilai.Print Tab(7); "Kode Nilai";
FrmCetakLayarNilai.Print Tab(20); "Nama Siswa";
FrmCetakLayarNilai.Print Tab(45); "Kelas";
FrmCetakLayarNilai.Print Tab(55); "Nilai Akhir"
FrmCetakLayarNilai.Print Tab(1); mgrs

Microsoft Visual Basic 6.0

164

msubtotalharga = 0
mbaris = 0
Do While Not Data1.Recordset.EOF And mbaris <= 30
mno = mno + 1
mharga = Data1.Recordset!Nilaiakhir
FrmCetakLayarNilai.Print Tab(1); Data1.Recordset!Nis;
FrmCetakLayarNilai.Print Tab(7); Data1.Recordset!KodeNilai;
FrmCetakLayarNilai.Print Tab(20); Data1.Recordset!Namasiswa;
FrmCetakLayarNilai.Print Tab(45); Data1.Recordset!Kelas;
FrmCetakLayarNilai.Print Tab(55); Data1.Recordset!Nilaiakhir
msubtotalharga = msubtotalharga + mharga
mbaris = mbaris + 1
Data1.Recordset.MoveNext

Loop
mtotalharga = mtotalharga + msubtotalharga
FrmCetakLayarNilai.Print Tab(1); mgrs
FrmCetakLayarNilai.Print Tab(20); "Jumlah";
FrmCetakLayarNilai.Print Tab(55); rkanan(mtotalharga, "###,###")
FrmCetakLayarNilai.Print Tab(20); "Bidang Studi";
FrmCetakLayarNilai.Print Tab(55); rkanan(mno, "###,###")
ratarata = mtotalharga / mno
FrmCetakLayarNilai.Print Tab(20); "Rata-rata";
FrmCetakLayarNilai.Print Tab(55); rkanan(ratarata, "###,###")
FrmCetakLayarNilai.Print Tab(1); mgrs

Loop
End Sub

Private Sub cetakkeprinter()
Dim msubtotal, mtotal As Long
Dim mno, mhal, mbaris As Integer
Dim mjumlah As Double
Dim mgrs As String
Printer.Font = "Courier New"
Data1.Recordset.MoveFirst
mtotalharga = 0
mno = 0
Do While Not Data1.Recordset.EOF
Printer.Print
Printer.Print
Printer.FontBold = True
Printer.FontSize = 10
Printer.Print Tab(10); "Data Nilai Siswa"
Printer.Print Tab(10); "Tanggal Cetak :"; Format(Date, "DD-MM-YYYY")
Printer.FontBold = False
Printer.Print
mgrs = String$(65, "-")
Printer.Print Tab(1); mgrs
Printer.Print Tab(1); "Nis";
Printer.Print Tab(7); "Kode Nilai";
Printer.Print Tab(20); "Nama Siswa";
Printer.Print Tab(45); "Kelas";
Printer.Print Tab(55); "Nilai Akhir"
Printer.Print Tab(1); mgrs
msubtotalharga = 0
mbaris = 0
Do While Not Data1.Recordset.EOF And mbaris <= 30
mno = mno + 1

Microsoft Visual Basic 6.0

165

mharga = Data1.Recordset!Nilaiakhir
Printer.Print Tab(1); Data1.Recordset!Nis;
Printer.Print Tab(7); Data1.Recordset!KodeNilai;
Printer.Print Tab(20); Data1.Recordset!Namasiswa;
Printer.Print Tab(45); Data1.Recordset!Kelas;
Printer.Print Tab(55); Data1.Recordset!Nilaiakhir
msubtotalharga = msubtotalharga + mharga
mbaris = mbaris + 1
Data1.Recordset.MoveNext

Loop
mtotalharga = mtotalharga + msubtotalharga
Printer.Print Tab(1); mgrs
Printer.Print Tab(20); "Jumlah";
Printer.Print Tab(55); rkanan(mtotalharga, "###,###")
Printer.Print Tab(20); "Bidang Studi";
Printer.Print Tab(55); rkanan(mno, "###,###")
ratarata = mtotalharga / mno
Printer.Print Tab(20); "Rata-rata";
Printer.Print Tab(55); rkanan(ratarata, "###,###")
Printer.Print Tab(1); mgrs

Loop
End Sub

Private Function rkanan(NData, CFormat) As String
rkanan = Format(NData, CFormat)
rkanan = Space(Len(CFormat) - Len(rkanan)) + rkanan

End Function

116.

Klik ganda didalam CommandButton yang berjudul Cetak ke layar, maka
akan tampil jendela Code. Masukkan kode dibawah ini.

Private Sub CmdCetakkeLayar_Click()
FrmCetakLayarNilai.Show
CetakLayarNilai

End Sub

117.

Klik ganda didalam CommandButton yang berjudul Cetak ke printer,
maka akan tampil jendela Code. Masukkan kode dibawah ini.

Private Sub CmdCetakkePrinter_Click()
pesan = MsgBox("Apakah printer sudah siap cetak ?", vbYesNo, "Persiapan")
If pesan = vbYes Then
cetakkeprinter
Printer.EndDoc

Else

pesan = MsgBox("Siapkan dulu printernya ?", 0, "Persiapan")

End If
End Sub

118.

Klik ganda didalam CommandButton yang berjudul Tutup, maka akan
tampil jendela Code. Masukkan kode dibawah ini.

Private Sub Command3_Click()
Unload Me
FrmMenuUtama.Enabled = True
FrmMenuUtama.SetFocus

End Sub

Microsoft Visual Basic 6.0

166

You're Reading a Free Preview

Mengunduh
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->