Anda di halaman 1dari 26

LABORATORIUM KOMPUTER SMA STELLA DUCE I MATERI : Visual Basic 6.

0 Penuntun Praktikum ke-1 Visual Basic adalah salah satu bahasa pemrograman komputer. Bahasa pemrograman adalah perintah-perintah yang dimengerti oleh komputer untuk melakukan tugas-tugas tertentu. Bahasa pemrograman Visual Basic, yang dikembangkan oleh Microsoft sejak tahun 1991, merupakan pengembangan dari pendahulunya yaitu bahasa pemrograman BASIC (Beginners All-purpose Symbolic Instruction Code) yang dikembangkan pada era 1950-an. Visual Basic merupakan salah satu Development Tool yaitu alat bantu untuk membuat berbagai macam program komputer, khususnya yang menggunakan sistem operasi Windows. Visual Basic merupakan salah satu bahasa pemrograman komputer yang mendukung object (Object Oriented Programming = OOP). Dalam pemrograman berbasis obyek (OOP), anda perlu memahami istilah object, property, method dan event sebagai berikut : Object : komponen di dalam sebuah program Property : karakteristik yang dimiliki object Method : aksi yang dapat dilakukan oleh object Event : kejadian yang dapat dialami oleh object 1 2 3

7 4 5

Keterangan : 1 : Tittle bar 2 : Menu bar 3 : Toolbar 4 : Toolbox 5 : Form

8 6 : Project Explorer : tampilan project dan form 7 : Properties Window : pengarutran atribut objek 8: Form layout: Posisi form pada saat di start

Visual Basic 6.0

Ubah tampilan pada menu View 1. Cobalah masukkan beberapa objek toolbox dibawah ini ada form, dan perhatikan perbedaannya. Label, Text,box, frame, command button, option button, checkbox, combo box, list box, horizontal scroll bar, vertical scroll bar, timer, shape, line 2. Klik

Private Sub Command1_Click() Command1.Caption = "SMU Stella Duce 1" End Sub Private Sub Form_Click() Form1.Caption = "Microsoft Visual Basic 6.0" End Sub

Ubah di properties, caption . Ubah di properties, text

label
Private Sub Command1_Click() Label3.Caption = Val(Text1.Text) + val(Text2.Text) End Sub

Visual Basic 6.0

Latihan 1.

Private Sub Command1_Click() Label3.Caption = Val(Text1.Text) * Val(Text2.Text) End Sub

2.

Private Sub Command1_Click() Label4.Caption = (Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)) / 3 End Sub

Visual Basic 6.0

LABORATORIUM KOMPUTER SMA STELLA DUCE I

MATERI : Visual Basic 6.0 Penuntun Praktikum ke-2

Latihan:

Samakan ukuran object, format make samesize,both Ubah bentuk dan warna tulisan

Properties Tooltiptext: Jangan masukkan angka nol Ubah background form,properti es,backcolor

Properties,Border style:fix singled

Private Sub Command1_Click() Label4.Caption = Val(Text1.Text) + Val(Text2.Text) End Sub Private Sub Command2_Click() Label4.Caption = Val(Text1.Text) * Val(Text2.Text) End Sub Private Sub Command3_Click() Label4.Caption = Val(Text1.Text) / Val(Text2.Text) End Sub 1. txtpesan cmdmasuk txtjumlah Private Sub Command1_Click() list1.AddItem Text1.Text & "," & Text2.Text & "porsi" End Sub Private Sub Command2_Click() Text1.Text = "" Text2.Text = "" Text1.SetFocus End Sub

lstdaftar

cmdlagi

2.

Private Sub Command1_Click() Combo1.AddItem Combo1.Text Combo1.SetFocus Combo1.Text = "" End Sub Private Sub Command2_Click() Label2.Caption = Combo1.ListCount End Sub Private Sub Command3_Click() End End Sub

LABORATORIUM KOMPUTER SMA STELLA DUCE I

MATERI : Visual Basic 6.0 Penuntun Praktikum ke-3

Latihan

Private Sub cmdexit_Click() Unload Me End Sub Private Sub optbatak_Click() lblresult.Caption = "Lo mo do rohangku tu ho" End Sub Private Sub optcina_Click() lblresult.Caption = "Wo Ai Ni" End Sub Private Sub optinggris_Click() lblresult.Caption = "I Love You" End Sub Private Sub optjawa_Click() lblresult.Caption = "Aku Tresno Kowe" End Sub Private Sub optjerman_Click() lblresult.Caption = "Ich Liebe Dich" End Sub

Laboratorium Komputer SMA Stella Duce I6.0 MATERI : Visual Basic Yogyakarta Materi : Visual Basic 6.0
Penuntun Praktikum ke-4

LABORATORIUM KOMPUTER SMA STELLA DUCE I

Penuntun

1.

Txtnilai1 Txtnilai2 lblrata

cmdrata

lblket

Keterangan : Jika Rata-rata <=60 maka keterangan GAGAL Jika Rata-rata >60 maka keterangan LULUS
2. txtisian chkbold chkitalic chkunderline

3.

Image1, Visible:false, Strecth: true, Picture:

Password Salah :

Password Benar

Timer1 , Enabled:false, Interval: 500 Erase : nama, password + Gambar tidak tampil

List Program: 1. Private Sub cmdrata_Click() lblrata.Caption = (nilai1 + nilai2) / 2 If lblrata.Caption <= 60 Then lblket.Caption = "GAGAL" End If If lblrata.Caption > 60 Then lblket.Caption = "LULUS" End If End Sub 2. Private Sub chkbold_Click() If chkbold.Value = 1 Then txtisian.FontBold = True End If If chkbold.Value = 0 Then txtisian.FontBold = False End If End Sub Private Sub chkitalic_Click() If chkitalic.Value = 1 Then txtisian.FontItalic = True End If If chkitalic.Value = 0 Then txtisian.FontItalic = False End If End Sub Private Sub chkunderline_Click() If chkunderline.Value = 1 Then txtisian.FontUnderline = True End If If chkunderline.Value = 0 Then txtisian.FontUnderline = False End If End Sub

3. Private Sub command1_Click() If text2.Text = "12345" Then MsgBox "Selamat Gambar anda akan muncul",vbokonly , "Kotak Gambar" Image1.visible=true Timer1.enabled=true Else MsgBox "Ayo coba lagi..?",vbokonly , "Coba lagi" Text2.text = Text2.setfocus End If End Sub Private Sub Timer1_Timer() gambar.Visible = Not gambar.Visible End Sub Private Sub command1_Click() Text1.text = Text2.text = Text2.setfocus Image1.visible=false Timer1.enabled=false End If

LABORATORIUM KOMPUTER SMA STELLA DUCE I

MATERI : Visual Basic 6.0 Penuntun Praktikum ke-5 Materi : Inputbox dan Select Case
1. Buat form seperti di bawah ini dan tambahkan timer dan image

Password salah, di klik OK kembali ke kotak password

Password benar

2.

Blinking
Petunjuk: Berat Ideal=(tinggi - 100) - ((tinggi - 100) * 0.1) Selisih = berat badan-berat ideal Ketentuan : Selisih > 5: "gemuk" selisih -5 sampai 5: "ideal" selisih <5 : "kurus"

List Program: 1. Private Sub cmdlanjut_Click() If txtpsw.Text = "stc1" Then MsgBox "Password Anda Benar", , "Pendaftaran" inp1 = InputBox("Masukan NIS", "NIS") inp2 = InputBox("Masukan NAMA", "NAMA") inp3 = InputBox("Masukan ALAMAT", "ALAMAT") lblket.Caption = inp1 + "," + inp2 + "," + inp3 lblselamat.FontSize = 16 lblselamat.Caption = "SELAMAT,ANDA BERHASIL!!!" Timer1.Enabled = True gambar.Visible = True Else MsgBox "Password Anda Salah!,Ulangi Lagi", vbExclamation, "WARNING" txtpsw.Text = "" txtpsw.setfocus End If End Sub Private Sub Timer1_Timer() gambar.Visible = Not gambar.Visible End Sub 2. Private Sub Command1_Click() tinggi = InputBox("Masukkan tinggi anda", "Tinggi anda") berat = InputBox("Masukkan berat anda", "Berat anda") BI = (tinggi - 100) - ((tinggi - 100) * 0.1) MsgBox "Berat ideal anda adalah " & BI, vbInformation, "Berat Ideal" selisih = berat - BI Select Case selisih Case Is > 5: Label1.Caption = text1.Text & " " & "anda termasuk " & "gemuk" Case -5 To 5: Label1.Caption = text1.Text & " " & "anda termasuk " & "ideal" Case Else: Label1.Caption = text1.Text + " " + "anda termasuk " + "kurus" End Select End Sub Private Sub Command2_Click() End End Sub

LABORATORIUM KOMPUTER SMA STELLA DUCE I

MATERI : Visual Basic 6.0 Penuntun Praktikum ke-6

Latihan 1. Cari 2 buah gambar di internet (teknologi lama dan baru), simpan di folder kelas Buat form seperti di bawah ini dan tambahkan timer(enable:false, interval:200) dan image (strecth:true), kosongkan image. Tampilkan gambar, dengan code seperti di bawah ini Image1.picture=Loadpicture(D:\kelas\namafile.jpg)

Program : Private Sub Command1_Click() Gambar1.Picture = LoadPicture("c:\program files\Microsoft Visual Studio\common\graphics\metafile\business\computer.wmf") MsgBox "Anda cukup modern !", vbOKOnly, "Keterangan" End Sub Private Sub Command2_Click() Gambar1.Picture = LoadPicture("c:\program files\Microsoft Visual Studio\common\graphics\metafile\business\typewrtr.wmf") MsgBox "Anda kuno sekali !", vbOKOnly, "Keterangan" End Sub

2.

Timer1(mengacak angka 1-10) Interval :200 Enable :False

Timer3(mengu bah font dan forecolor) Interval100

Lblacak(angka acak) Aligment:center

Image1 Metafile-money Visible:false

Timer2 (Blinking) Interval :100 Enable:false

Private Sub cmdputar_Click() Timer1.Enabled = True Timer2.Enabled = False gambar.Visible = False End Sub Private Sub cmdstop_Click() Timer1.Enabled = True If lblacak.Caption = "7" Then MsgBox "Hore !!!!,Anda beruntung!!!", vbInformation, "Hasil" Timer2.Enabled = True Else MsgBox "TIDAK TEPAT DI NOMOR 7!!!", vbCritical, "Hasil" Timer2.Enabled = False End If End Sub Private Sub Timer1_Timer() lblacak.Caption = Int(Rnd * 10) End Sub Private Sub Timer2_Timer() gambar.Visible = Not gambar.Visible End Sub Private Sub Timer3_Timer() lblnama.FontSize = Int(Rnd * 36) + 1 lblnama.ForeColor = QBColor(Rnd * 10) End Sub

Common Graphics Metafile business Yen Pound Moneybag Guilder

List program : 1. Private Sub cmdputar_Click() Timer2.Enabled = False Image1.Visible = False Timer1.Enabled = True End Sub

Interval 100

Private Sub Cmdstop_Click() Timer1.Enabled = False If Lblacak.Caption = "7" Then MsgBox "Hore!!!!!!, Anda beruntung!!!", vbInformation, "hasil" Timer2.Enabled = True Else MsgBox "Selamat Tinggal!!!", vbCritical, "hasil" Timer2.Enabled = False End If End Sub Private Sub Timer1_Timer() Lblacak.Caption = Int(Rnd * 10)

2.Private Sub Check1_Click() If Check1.Value = 1 Then Image1.Visible = True Image2.Visible = True Timer1.Enabled = True Else Image1.Visible = False Image2.Visible = False End If End Sub Private Sub Check2_Click() If Check1.Value = 1 Then Image3.Visible = True Image4.Visible = True Timer1.Enabled = True Else Image3.Visible = False Image4.Visible = False End If End Sub

CommonGraphicsIcons-Flags

End Sub Private Sub Timer2_Timer() Image1.Visible = Not Image1.Visible End Sub Private Sub Timer3_Timer() Lblnama.FontSize = Int(Rnd * 36) + 1 Lblnama.ForeColor = QBColor(Rnd * 15) End Sub

Private Sub Check3_Click() If Check1.Value = 1 Then Image5.Visible = True Image6.Visible = True Timer1.Enabled = True Else Image5.Visible = False Image6.Visible = False End If End Sub Private Sub Check4_Click() If Check1.Value = 1 Then Image7.Visible = True Image8.Visible = True Timer1.Enabled = True Else Image7.Visible = False Image8.Visible = False End If End Sub Private Sub Timer1_Timer() If Check1.Value = 1 Then Image1.Visible = Not Image1.Visible Image2.Visible = Not Image2.Visible Else Image1.Visible = False Image2.Visible = False End If If Check2.Value = 1 Then Image3.Visible = Not Image3.Visible Image4.Visible = Not Image4.Visible Else Image3.Visible = False Image4.Visible = False End If If Check3.Value = 1 Then Image5.Visible = Not Image5.Visible Image6.Visible = Not Image6.Visible Else Image5.Visible = False Image6.Visible = False End If If Check4.Value = 1 Then Image7.Visible = Not Image7.Visible Image8.Visible = Not Image8.Visible Else Image7.Visible = False Image8.Visible = False End If End Sub

LABORATORIUM KOMPUTER SMA STELLA DUCE I

MATERI : Visual Basic 6.0 Penuntun Praktikum ke-7

Latihan :

Jika password benar, muncul teks anda dapat melanjutkan dengan tampilan blinking Jika password salah

Jika Yes, kembali isi password, jika No keluar dari form Tampil gambar, jika di klik pilih, muncul kotak input

Private Sub cmdok_Click() If txtpassword.Text = "damzholic" Then timer1.Enabled = True lblpassword.Caption = "anda dapat melanjutkan" Else msg = MsgBox("password salah, anda mau terus", vbYesNo, "salah") If msg = vbYes Then txtpassword.Text = "" txtpassword.SetFocus Else: End End If End If End Sub Private Sub cmdpilih_Click() inp = InputBox("masukkan pilihan anda", "pilih gambar") Select Case inp Case 1: Image1.Picture = LoadPicture("C:\Documents and Settings\Meilina\My Documents\doggie bobo.jpg") Case 2: Image1.Picture = LoadPicture("C:\Documents and Settings\Meilina\My Documents\berdoa.jpg") Case 3: Image1.Picture = LoadPicture("C:\Documents and Settings\Meilina\My Documents\rumametmet.jpg") End Select End Sub Private Sub timer1_Timer() lblpassword.Visible = Not lblpassword.Visible End Sub

Common Graphics Metafile business Yen Pound Moneybag Guilder

List program : 2.Private Sub Check1_Click() If Check1.Value = 1 Then Image1.Visible = True Image2.Visible = True Timer1.Enabled = True Else Image1.Visible = False Image2.Visible = False End If End Sub Private Sub Check2_Click() If Check1.Value = 1 Then Image3.Visible = True Image4.Visible = True Timer1.Enabled = True Else Image3.Visible = False Image4.Visible = False End If End Sub Private Sub Check3_Click

Interval 100
If Check1.Value = 1 Then Image5.Visible = True Image6.Visible = True Timer1.Enabled = True Else Image5.Visible = False Image6.Visible = False End If End Sub Private Sub Check4_Click() If Check1.Value = 1 Then Image7.Visible = True Image8.Visible = True Timer1.Enabled = True Else Image7.Visible = False Image8.Visible = False End If End Sub

CommonGraphicsIcons-Flags

Private Sub Timer1_Timer() If Check1.Value = 1 Then Image1.Visible = Not Image1.Visible Image2.Visible = Not Image2.Visible Else Image1.Visible = False Image2.Visible = False End If If Check2.Value = 1 Then

Image3.Visible Image4.Visible Else Image3.Visible Image4.Visible

= Not Image3.Visible = Not Image4.Visible = False = False

End If If Check3.Value = 1 Then Image5.Visible = Not Image5.Visible Image6.Visible = Not Image6.Visible Else Image5.Visible = False Image6.Visible = False End If If Check4.Value = 1 Then Image7.Visible = Not Image7.Visible Image8.Visible = Not Image8.Visible Else Image7.Visible = False Image8.Visible = False End If End Sub

LABORATORIUM KOMPUTER SMA STELLA DUCE I

MATERI : Visual Basic 6.0 Penuntun Praktikum ke-8

Tujuan : Siswa dapat membuat program sederhana menggunakan toolbox (form ) serta mengubah jenis huruf, ukuran,warna dari properties, menuliskan program pada code dan menjalankan program.

1. .

Private Sub cmdbesar_Click() Form1.Height = Form1.Height + 450 Form1.Width = Form1.Width + 450 End Sub Private Sub cmdganti_Click() Form1.BackColor = QBColor(Rnd() * 15) End Sub Private Sub lblambil_Click() Form1.Caption = txtjudul.Text End Sub

2.
Text1 Name : Txtwarna Hscrollbar1 Name : hsbMerah Hscrollbar2 Name :hsbbiru Hscrollbar3 Name: hsbBiru Command1 Name :cmdkeluar Caption: &Keluar Name:cmdkeluar

Private Sub cmdkeluar_Click() end End Sub Private Sub hsbbiru_Change() warna End Sub Private Sub hsbhijau_Change() warna End Sub Private Sub hsbmerah_Change() warna End Sub Private Sub warna() txtwarna.BackColor = RGB(hsbmerah.Value, hsbhijau.Value, hsbbiru.Value) End Sub

LABORATORIUM KOMPUTER SMA STELLA DUCE I

MATERI : Visual Basic 6.0 Penuntun Praktikum ke-9

Tujuan : Siswa dapat membuat program sederhana menggunakan menu.

Private Sub Combo1_Click() Select Case Combo1 Case "Gado-Gado": Text2.Text = "7000" Case "Rendang": Text2.Text = "8000" Case "Ketupat Sayur": Text2.Text = "9000" Case "Coca Cola": Text2.Text = "1200" Case "Fanta": Text2.Text = "1500" Case "Teh Botol": Text2.Text = "2000" Case "Semangka": Text2.Text = "500" Case "Melon": Text2.Text = "700" Case "Apel": Text2.Text = "1500" End Select Text3.Text = "" Text3.SetFocus End Sub

Private Sub Command1_Click() If Text3.Text = "" Then MsgBox "isi dulu dong!", vbCritical, "pesanan" Text3.SetFocus Else List1.AddItem Combo1.Text + " " + Text3.Text List2.AddItem Val(Text2.Text) * Val(Text3.Text) End If End Sub Private Sub Command3_Click() For i = 0 To Val(List2.ListCount - 1) pol = pol + Val(List2.List(i)) Next i Label5.Caption = pol End Sub Private Sub Form_Load() Option1.Value = False Option2.Value = False Option3.Value = False End Sub Private Sub mnuabout_Click() MsgBox "Cafe Enak Banget " & Chr(10) & _ "Pemilik : Arnold S" & Chr(10) & _ "Lokasi : Jl.Santai no.7" & Chr(10) &_ "Cabang : Jl.Tol km.8 ", vbInformation, "Information" End Sub Private Sub mnuexit_Click() MsgBox "Keluar dari program", vbOKOnly + vbQuestion End End Sub

Private Sub mnupesan_Click() Text3.Text = "" Text3.SetFocus End Sub Private Sub mnutot_Click() For i = 0 To Val(List2.ListCount - 1) pol = pol + Val(List2.List(i)) Next i Label5.Caption = pol End Sub Private Sub Option1_Click() Combo1.Clear If Option1.Value = True Then Combo1.AddItem "Gado-Gado" Combo1.AddItem "Rendang" Combo1.AddItem "Ketupat Sayur" End If End Sub Private Sub Option2_Click() Combo1.Clear If Option2.Value = True Then Combo1.AddItem "Coca Cola" Combo1.AddItem "Fanta" Combo1.AddItem "Teh Botol" End If End Sub Private Sub Option3_Click() Combo1.Clear If Option3.Value = True Then Combo1.AddItem "Semangka" Combo1.AddItem "Melon" Combo1.AddItem "Apel" End If End Sub