Professional Documents
Culture Documents
(Name) Lbljudul
Label1
Caption Belajar VB 1
(Name) Lbltext
Label2
Caption (dikosongkan)
(Name) CmdPink
Command1
Caption PINK
(Name) Cmdhitam
Command2
Caption Hitam
(Name) CmdBiru
Command3
Caption BIRU
(Name) CmdHijau
Command5
Caption Hijau
(Name) CmdKuning
Command6
Caption Kuning
(Name) frmtext
Frame 1
Caption Pilih Warna Text
(Name) frmbackground
Frame 2
Caption Pilih Warna Background
bola.BackColor = vbRed
End Sub
bola.BackColor = vbGreen
End Sub
text1.ForeColor = &HFF80FF
End Sub
text1.Caption = "Hitam"
text1.ForeColor = vbBlack
End Sub
Private Sub Command5_Click()
bola.BackColor = vbYellow
End Sub
text1.ForeColor = vbBlue
End Sub
Latihan 2
(Name) Lbljudul
Label1
Caption Kalkulator Mini
(Name) Lblbil1
Label2
Caption Masukan Bilangan1
(Name) Lblbil3
Label3
Caption Masukan Bilangan2
(Name) Lblhasil
Label4
Caption Hsdil Perhitungan
(Name) Txtbil1
Textbox1
Text (kosongkan)
(Name) Txtbil2
Textbox2
Text (kosongkan)
(Name) Txthasil
Textbox3
Text (kosongkan)
(Name) Cmdtambah
Command1
Caption +
(Name) Cmdkali
Command2
Caption x
(Name) Cmdkurang
Command3
Caption -
(Name) Cmdbagi
Command4
Caption /
(Name) CmdKeluar
Command5
Caption Keluar
bil1 = txtbil1.Text
bil2 = txtbil2.Text
txthasil.Text = hasil
End Sub
bil1 = txtbil1.Text
bil2 = txtbil2.Text
txthasil.Text = hasil
End Sub
bil1 = txtbil1.Text
bil2 = txtbil2.Text
txthasil.Text = hasil
End Sub
bil1 = txtbil1.Text
bil2 = txtbil2.Text
txthasil.Text = hasil
End Sub
Latihan 3
Combobox1:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.Text
Case “Nasi Uduk”
Label2.Text = “Rp. 3500”
hrgmakanan = 3500
Case “Bakso”
Label2.Text = “Rp. 6000”
hrgmakanan = 6000
Case “Mie Ayam”
Label2.Text = “Rp. 7000”
hrgmakanan = 7000
End Select
End Sub
variabel di Form1:
Public Class Form1
Public hrgmakanan, hrgminuman As Integer
Combobox2:
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Select Case ComboBox2.Text
Case “Es Jeruk”
Label4.Text = “Rp. 3000”
hrgminuman = 3000
Case “Jus Alpukat”
Label4.Text = “Rp. 7000”
hrgminuman = 7000
Case “Teh Manis”
Label4.Text = “Rp. 4000”
hrgminuman = 4000
End Select
End Sub
Sub-routine Public:
Public Sub New()
If Text1.Text = “” Then
MsgBox (“Isi dulu Nama anda”)
Else
MsgBox (“Nama Saya” + Text1.Text + “Dan saya sedang belajar Visual Basic
6.0”)
End If
latihan 3
(Name) Lbluser
Label1
Caption User ID
(Name) Lbluser
Label2
Caption Nama Lengkap
(Name) Lbluser
Label3
Caption Password
(Name) Lbluser
Label4
Caption Ketik Ulang Password
(Name) Lbluser
Label5
Caption Type User
(Name) Cmdtambah
Command1
Caption Tam&bah
(Name) Cmdsimpan
Command2
Caption Sim&pan
(Name) Cmdhapus
Command3
Caption Ha&pus
(Name) Cmdtambah
Command4
Caption Bat&al
Username Text 25
Nama Text 25
Password Text 10
Type Text 10
Oh iya, jangan lupa untuk menambahkan references “Microsoft Activex Data
objeck 2.0 Library” agar database tersebut terhubung pada program Visual Basic
Anda.
tombol “Tambah”:
Text1.Enabled = True
Text1.SetFocus
Text1.Text = “”
Text2.Text = “”
CmdTambah.Enabled = False
CmdSimpan.Enabled = True
CmdSimpan.Caption = “Simpan”
CmdKeluar.Caption = “Batal”
Tombol “Simpan”:
If Text4.Text <> Text3.Text Then
MsgBox “Password tidak sama, ketik ulang password “, vbInformation
Exit Sub
End If
If Text1.Text = “” Or Text2.Text = “” Or Text3.Text = “” Or Text4.Text = “” Or
Text5.Text = “” Then
MsgBox “DATA tidak boleh kosong!”, _
vbInformation + vbOKOnly, “Perhatian”
Text1.SetFocus
Else
‘On Error Resume Next
If TbSimpan.Caption = “Simpan” Then
SqlInsert = “”
SqlInsert = “INSERT INTO UsrKontrol” _
& ” (UsrName,” _
& ” Nama,” _
& ” Pass,” _
& ” Tipe)” _
& ” VALUES(‘” & Text1.Text & “‘,'” _
& Text2 & “‘,'” _
& Text3 & “‘,'” _
& Text5.Text & “‘)”
MsgBox “data telah disimpan”, vbInformation, “keterangan”
DbKoneksi.Execute SqlInsert, , adCmdText
Rs_UsrKontrol.Requery
Call FormNormal
Call Form_Load
ElseIf TbSimpan.Caption = “Ubah” Then
‘ eksekusiSQL “update UsrKontrol set UsrName='” & safeSQL(Text1) &
“‘,Nama='” & safeSQL(Text2) & “‘, Pass='” & safeSQL(Text3) & “‘ tipe='” &
safeSQL(Text5) & “‘”
eksekusiSQL “update UsrKontrol set nama='” & safeSQL(Text2) & “‘,pass='” &
safeSQL(Text3) & “‘, tipe='” & safeSQL(Text5) & “‘ where usrname='” &
safeSQL(Text1) & “‘”
MsgBox “Update data sukses.”, vbInformation
Call FormNormal
Call Form_Load
End If
End If
Tombol “Hapus”:
Konfirmasi = MsgBox(“Anda yakin akan menghapus data ini?”, vbYesNo +
vbQuestion, “informasi”)
If Konfirmasi = vbYes Then
SqlDelete = “DELETE FROM UsrKontrol WHERE ” _
& ” Usrname='” & Text1.Text & “‘”
DbKoneksi.Execute SqlDelete, , adCmdText
Rs_UsrKontrol.Requery
Call FormNormal
Call Form_Load
Else
Call FormNormal
End If
Tombol “Batal”:
If TbKeluar.Caption = “Keluar” Then
‘ frmMain.Enabled = True
Unload Me
Else
FormNormal
End If
Program pada Form_Load:
Sub FormMati()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Text = False
End Sub
Latihan 5
'Menentkan Umur
LblUmur.Caption = DateDiff("yyyy", DTPicker.Value, Date)
'Menentukan Hari
KodeHari = Weekday(DTPicker.Value)
Select Case KodeHari
Case 1: hari = "Minggu"
Case 2: hari = "Senin"
Case 3: hari = "Selasa"
Case 4: hari = "Rabu"
Case 5: hari = "Kamis"
Case 6: hari = "Jumat"
Case 7: hari = "Sabtu"
End Select
LblHari.Caption = hari
'Menentukan Zodiak
If Bulan = 1 Then
LblZodiak.Caption = IIf(Tanggal <= 19, "Capricorn", "Aquarius")
ElseIf Bulan = 2 Then
LblZodiak.Caption = IIf(Tanggal <= 19, "Aquarius", "Pisces")
ElseIf Bulan = 3 Then
LblZodiak.Caption = IIf(Tanggal <= 20, "Pisces", "Aries")
ElseIf Bulan = 4 Then
LblZodiak.Caption = IIf(Tanggal <= 20, "Aries", "Taurus")
ElseIf Bulan = 5 Then
LblZodiak.Caption = IIf(Tanggal <= 21, "Taurus", "Gemini")
ElseIf Bulan = 6 Then
LblZodiak.Caption = IIf(Tanggal <= 21, "Gemini", "Cancer")
ElseIf Bulan = 7 Then
LblZodiak.Caption = IIf(Tanggal <= 21, "Cancer", "Leo")
ElseIf Bulan = 8 Then
LblZodiak.Caption = IIf(Tanggal <= 21, "Leo", "Virgo")
ElseIf Bulan = 9 Then
LblZodiak.Caption = IIf(Tanggal <= 22, "Virgo", "Libra")
ElseIf Bulan = 10 Then
LblZodiak.Caption = IIf(Tanggal <= 23, " Libra", "Scorpio")
ElseIf Bulan = 11 Then
LblZodiak.Caption = IIf(Tanggal <= 22, "Scorpio", "Sagitarius")
Else
LblZodiak.Caption = IIf(Tanggal <= 22, "Sagitarius", "Capricorn")
End If
LblHari.Visible = True
LblUmur.Visible = True
LblZodiak.Visible = True
LblKeterangan.Visible = True
hari.Visible = True
umur.Visible = True
zodiak.Visible = True
keterangan.Visible = True
tahun.Visible = True
End Sub