Modul Mata kuliah : Pemrograman Visual Basic Dasar
Kode mata kuliah : PR140
Sks :2
Private Sub clear_Click()
Text1.Text = "" Text2.Text = "" Text1.SetFocus End Sub
Private Sub tampil_Click()
Text2.Text = Text1.Text End Sub
Private Sub ok_Click()
lblhello.Caption = "Hello " + txtnama.Text + ", Selamat Datang di Dunia Visual" End Sub
Private Sub selesai_Click()
Unload Me End Sub Private Sub bagi_Click() Text3.Text = Val(Text1.Text) / Val(Text2.Text) End Sub
Private Sub kali_Click()
Text3.Text = Val(Text1.Text) * Val(Text2.Text) End Sub
Private Sub kurang_Click()
Text3.Text = Val(Text1.Text) - Val(Text2.Text) End Sub Private Sub tambah_Click() Text3.Text = Val(Text1.Text) + Val(Text2.Text) End sub
Private Sub proses_Click()
txtjum.Text = Val(txtpensil.Text) + Val(txtpulpen.Text) + Val(txtbuku.Text) + Val(txtgaris.Text) txtdis.Text = 0.1 * Val(txtjum.Text) txttotal.Text = Val(txtjum.Text) - Val(txtdis.Text) End Sub Dim hasil As Double Private Sub hitung_Click() hasil = Val(0.4 * Text1.Text) + Val(0.6 * Text2.Text) Text3.Text = hasil If hasil >= 90 Then Text4.Text = "Memuaskan" Else If hasil >= 80 Then Text4.Text = "Baik" Else If hasil >= 70 Then Text4.Text = "Cukup" Else Text4.Text = "Kurang" End If End If End If End Sub
Buatlah program dengan ketentuan
1. Tombol tampil digunakan untuk menampilkan gaji pokok, tunjangan dan upah lembur Jika Golongan A maka Gaji Pokok 500000, Tunjangan 200000 dan Upah Lembur 10000 Jika Golongan B maka Gaji Pokok 700000, Tunjangan 300000 dan Upah Lembur 20000 Jika Golongan C maka Gaji Pokok 900000, Tunjangan 400000 dan Upah Lembur 30000 2. Tombol hitung digunakan untuk Upah total didapat jika jam kerja > 8 jam dengan perhitungan Jam kerja-8 dikalikan dengan upah total, jadi jika jam kerja kurang dari 8 jam maka upah totalnya adalah 0 Total gaji didapat dari gaji pokok + tunjangan + upah lembur + upah total Private Sub optkod_Click(Index As Integer) Select Case Index Case 0 Text1.Text = "Sistem Basis Data" Text2.Text = 4 Text3.Text = "Keahlian" Case 1 Text1.Text = "Sistem Operasi" Text2.Text = 4 Text3.Text = "Keilmuan" Case 2 Text1.Text = "Sistem Informasi Manajemen" Text2.Text = 4 Text3.Text = "Keahlian" End Select End Sub
Private Sub hitung_Click()
If txtjamker.Text >= 8 Then txtupahtot.Text = Val(txtjamker.Text - 8) * Val(txtupah.Text) Else txtupahtot.Text = 0 End If txtgaji.Text = Val(Text4.Text) + Val(Text5.Text) + Val(txtupah.Text) + Val(txtupahtot.Text) End Sub
Private Sub tampil_Click()
If Text2.Text = "A" Then Text4.Text = 500000 Text5.Text = 200000 txtupah.Text = 10000 Else If Text2.Text = "B" Then Text4.Text = 700000 Text5.Text = 300000 txtupah.Text = 20000 Else If Text2.Text = "C" Then Text4.Text = 900000 Text5.Text = 400000 txtupah.Text = 30000 End If End If End If End Sub
Private Sub Check1_Click()
If Check1.Value = 1 And Check2.Value = 0 Then Text1 = "Soekarno" Else If Check2.Value = 1 And Check1.Value = 0 Then Text1 = "Hatta" Else If Check1.Value = 1 And Check2.Value = 1 Then Text1 = "Soekarno Hatta" Else If Check1.Value = 0 And Check2.Value = 0 Then Text1 = "" End If End If End If End If End Sub
Private Sub Check2_Click()
If Check1.Value = 1 And Check2.Value = 0 Then Text1 = "Soekarno" Else If Check2.Value = 1 And Check1.Value = 0 Then Text1 = "Hatta" Else If Check2.Value = 1 And Check1.Value = 1 Then Text1 = "Soekarno Hatta" Else If Check1.Value = 0 And Check2.Value = 0 Then Text1 = "" End If End If End If End If End Sub
Private Sub Check1_Click()
If Check1.Value = 1 Then Text1.FontBold = True Label1.Alignment = 0 Else Text1.FontBold = False Label1.Alignment = 1 End If If Check2.Value = 1 Then Text1.FontItalic = True Label1.Alignment = 0 Else Text1.FontItalic = False Label1.Alignment = 1 End If End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then Text1.FontItalic = True Label1.Alignment = 0 Else Text1.FontItalic = False Label1.Alignment = 1 End If End Sub Permintaan : Pada saat check objek bold “program visual basic 6.0” tercetak tebal, jika tidak maka sebaliknya. Begitu juga dengan tombol Italic, Pergunakan teks cetak rata kanan pada saat tercheck, jika tidak rata kiri
Listing Program
Private Sub Check1_Click()
If Check1.Value = 1 Then Text1.FontBold = True Label1.Alignment = 0 Else Text1.FontBold = False Label1.Alignment = 1 End If End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then Text1.FontItalic = True Label1.Alignment = 0 Else Text1.FontItalic = False Label1.Alignment = 1 End If End Sub
Private Sub Form_Load()
Text1.Text = "PROGRAM VISUAL BASIC 6.0" End Sub Private Sub Command1_Click() If chk1.Value = 1 Then a = 20000 Else a=0 End If If chk2.Value = 1 Then b = 30000 Else b=0 End If If chk3.Value = 1 Then c = 25000 Else c=0 End If d=a+b+c Text3.Text = d End Sub
Private Sub Option1_Click()
If Option1.Value = True Then Text2.Text = Option1.Caption End If End Sub
Private Sub Option2_Click()
If Option2.Value = True Then Text2.Text = Option2.Caption End If End Sub Private Sub Command1_Click() List1.AddItem Text1 Text1 = Clear Text1.SetFocus End Sub
Private Sub Command1_Click()
List1.AddItem Text1 Text1 = Clear Text1.SetFocus End Sub
Private Sub Command2_Click()
Text1 = List1.ListCount End Sub
Private Sub Command3_Click()
List1.RemoveItem List1.ListIndex End Sub
Private Sub Form_Load()
List1.AddItem "Ida" List1.AddItem "Maya" List1.AddItem "Dian" End Sub
Private Sub Command1_Click()
List1.AddItem Text1 Text1 = Clear Text1.SetFocus End Sub
Private Sub Command2_Click()
Text1 = List1.ListCount End Sub
Private Sub Command3_Click()
List1.RemoveItem List1.ListIndex End Sub
Private Sub Form_Load()
List1.AddItem "Ida" List1.AddItem "Maya" List1.AddItem "Dian" End Sub
Private Sub cmdpindah1_Click()
For x = 0 To List1.ListCount List2.AddItem List1.List(x) Next x List1.Clear End Sub
Private Sub cmdhapus_Click()
List1.RemoveItem List1.ListIndex End Sub
Private Sub cmdinput_Click()
List1.AddItem Text1 Text1 = Clear Text1.SetFocus End Sub
Private Sub cmdpindah_Click()
List2.AddItem List1.List(List1.ListIndex) List1.RemoveItem List1.ListIndex End Sub
Private Sub cmdpindah1_Click()
For x = 0 To List1.ListCount List2.AddItem List1.List(x) Next x List1.Clear End Sub Dim nama(5) As String Dim intc As Integer
Private Sub Form_Load()
intc = 1 Do While (intc <= 5) nama(intc) = InputBox("Ketikkan nama ke-" + _ Str(intc), "Menginput nama 5 kali") List1.AddItem nama(intc) intc = intc + 1 Loop End Sub