MODUL
PRAKTIKUM
VISUAL BASIC 2012
MODUL
3
INPUT
DAN OUTPUT
LATIHAN 1
1. 1. Buatlah sebuah aplikasi baru (File | New
Project | Standard EXE)
2.
2. Masukkan 3 TextBox, 3 Label dan 2 Button.
3.
3. Gantilah properties masing-masing komponen
seperti tertera dibawah ini :
Object |
Properties |
Value |
Form |
Text |
Belanja |
TextBox1 |
Text Name |
<kosong> txtHargaSatuan |
TextBox2 |
Text Name |
<kosong> txtJumlah |
TextBox3 |
Text Name |
<kosong> txtBayar |
Label1 |
Text |
Harga Satuan Rp. |
Label2 |
Text |
Jumlah Barang |
Label3 |
Text |
Bayar |
Button1 |
Text |
Proses |
Button2 |
Text |
Keluar |
4.
4. Masukkan code untuk Button Proses
Private Sub
Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
txtBayar.Text() =
Val(txtHargaSatuan.Text) * Val(txtJumlah.Text)
End Sub
5.
5. asukkan code untuk Button Keluar
Private Sub
Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
Me.Close()
End Sub
6.
6. Tekan F5 untuk menjalankan program
(Running)
LATIHAN 2
1.
1. Buatlah sebuah aplikasi baru (File | New
Project | Standard EXE)
2.
2. Masukkan 3 TextBox, 3 Label dan 2 Button
3.
3. Gantilah properties masing-masing komponen
seperti tertera dibawah ini :
Object |
Properties |
Value |
Form |
Text |
Input Nama |
TextBox1 |
Text Name |
<kosong> txtNama |
TextBox2 |
Text Name |
<kosong> txtAlamat |
TextBox3 |
Text Name |
<kosong> txtTelepon |
Label1 |
Text |
Nama |
Label2 |
Text |
Alamat |
Label3 |
Text |
Telepon |
Button1 |
Text |
Pesan |
Button2 |
Text |
Keluar |
4.
4. Masukkan code untuk Button Proses
Private Sub
Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
MsgBox(" Nama Anda
" & txtNama.Text & " dengan Alamat " &
txtAlamat.Text & " Telp " &
txtTelepon.Text)
End Sub
5.
5. Masukkan code untuk Button Keluar
Private Sub
Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
End
End Sub
6.
6. Tekan F5 untuk menjalankan program
(Running)
TUGAS PRAKTIKUM
1 1. Buatlah program kalkulator dengan operasi yang ada : penambahan, pengurangan,
pembagian, dan perkalian (Nama File ® ProjectTugas1Prak3.vbp)
2. Buat program untuk menghitung luas kubus, persegi panjang, dan lingkaran dengan
inputan panjang, lebar dan jari-jari dan tampilkan hasilnya
(Nama File ® ProjectTugas2Prak3.vbp)
3. Buat program menginputkan identitas diri (NIM, Nama, Jurusan, Jenjang dan Alamat) dan
tampilkan pada form yang berbeda (Nama
File ® ProjectTugas3Prak3.vbp)
Langkah Tugas Praktikum 1
Untuk properties dari
masing-masing object, saya contohkan seperti dibawah ini, dengan letak
masing-masing object disesuaikan dengan gambar diatas.
Form (Name) :
FormCalculator Text :
FormCalculator |
Textbox1 (Name) :
txtDisplay TextAlign :
Right Text : <kosongkan> Font Size : 12 TabIndex : 0 |
Button1 (Name) : btnPercent TabIndex : 1 Text : % |
Button2 (Name) :
btnClear TabIndex : 2 Text : Clear |
Button3 (Name) :
btnDelete TabIndex : 3 Text : Delete |
Button4 (Name) : btnExit TabIndex : 4 Text : Exit |
Button5 (Name) : btnSin TabIndex : 5 Text : Sin |
Button6 (Name) : btnCos TabIndex : 6 Text : Cos |
Button7 (Name) : btnTan TabIndex : 7 Text : Tan |
Button8 (Name) : btnDivide TabIndex : 8 Text : / |
Button9 (Name) : btn1 TabIndex : 9 Text : 1 |
Button10 (Name) : btn2 TabIndex : 10 Text : 2 |
Button11 (Name) : btn3 TabIndex : 11 Text : 3 |
Button12 (Name) : btnMultiply TabIndex : 12 Text : x |
Button13 (Name) : btn4 TabIndex : 13 Text : 4 |
Button14 (Name) : btn5 TabIndex : 14 Text : 5 |
Button15 (Name) : btn6 TabIndex : 15 Text : 6 |
Button16 (Name) : btnSubstract TabIndex : 16 Text : - |
Button17 (Name) : btn7 TabIndex : 17 Text : 7 |
Button18 (Name) : btn8 TabIndex : 18 Text : 8 |
Button19 (Name) : btn9 TabIndex : 19 Text : 9 |
Button20 (Name) : btnAdd TabIndex : 20 Text : + |
Button21 (Name) : btnNegate TabIndex : 21 Text : +/- |
Button22 (Name) : btn0 TabIndex : 22 Text : 0 |
Button23 (Name) : btnDot TabIndex : 23 Text : , |
Button24 (Name) : btnPower TabIndex : 24 Text : ^ |
Button25 (Name) : btnSquare TabIndex : 25 Text : x^2 |
Button26 (Name) : btnCube TabIndex : 26 Text : x^3 |
Button27 (Name) : btnLn TabIndex : 27 Text : Ln |
Button28 (Name) : btnReciprocal TabIndex : 28 Text : 1/x |
Button29 (Name) : btnSqrt TabIndex : 29 Text : Sqrt |
Button30 (Name) : btnEquals TabIndex : 30 Text : = |
Button31 (Name) : btnFactorial TabIndex : 31 Text : x! |
|
Berikutnya, Anda tinggal membuat coding dari kalkulator
tersebut. Jika Anda mengikuti semua setting properties seperti diatas, maka
codingnya saya contohkan seperti ini :
Public Class kalku Dim angka
As Double Dim hasil
As Double Dim
operasi As String Const Phi As Double =
3.14159265358979 Private Sub
a1_Click(sender As Object, e As EventArgs) Handles
a1.Click If
layar.Text = "0" Then
layar.Text = "1" Else
layar.Text = layar.Text & "1" End If End Sub Private Sub
a2_Click(sender As Object, e As EventArgs) Handles
a2.Click If
layar.Text = "0" Then
layar.Text = "2" Else
layar.Text = layar.Text & "2" End If End Sub Private Sub
a3_Click(sender As Object, e As EventArgs) Handles
a3.Click If
layar.Text = "0" Then
layar.Text = "3" Else
layar.Text = layar.Text & "3" End If End Sub Private Sub
a4_Click(sender As Object, e As EventArgs) Handles
a4.Click If
layar.Text = "0" Then
layar.Text = "4" Else
layar.Text = layar.Text & "4" End If End Sub Private Sub
a5_Click(sender As Object, e As EventArgs) Handles
a5.Click If
layar.Text = "0" Then
layar.Text = "5" Else
layar.Text = layar.Text & "5" End If End Sub Private Sub
a6_Click(sender As Object, e As EventArgs) Handles
a6.Click If
layar.Text = "0" Then
layar.Text = "6" Else
layar.Text = layar.Text & "6" End If End Sub Private Sub
a7_Click(sender As Object, e As EventArgs) Handles
a7.Click If
layar.Text = "0" Then
layar.Text = "7" Else
layar.Text = layar.Text & "7" End If End Sub Private Sub
a8_Click(sender As Object, e As EventArgs) Handles
a8.Click If
layar.Text = "0" Then
layar.Text = "8" Else
layar.Text = layar.Text & "8" End If End Sub Private Sub
a9_Click(sender As Object, e As EventArgs) Handles
a9.Click If
layar.Text = "0" Then
layar.Text = "9" Else
layar.Text = layar.Text & "9" End If End Sub Private Sub
a0_Click(sender As Object, e As EventArgs) Handles
a0.Click If
layar.Text = "0" Then
layar.Text = "0" Else
layar.Text = layar.Text & "0" End If End Sub Private Sub
klikkoma_Click(sender As Object, e As EventArgs) Handles
klikkoma.Click If
layar.Text = "0" Then
layar.Text = layar.Text + "." Else layar.Text = layar.Text + "." End If End Sub Private Sub
kliktambah_Click(sender As Object, e As EventArgs) Handles
kliktambah.Click If angka
= "0" Then
angka = Val(layar.Text) Else
angka = angka + Val(layar.Text) End If
operasi = "+"
layar.Text = "" End Sub Private Sub
klikkurang_Click(sender As Object, e As EventArgs) Handles
klikkurang.Click If angka
= "0" Then
angka = Val(layar.Text) Else
angka = angka - Val(layar.Text) End If
operasi = "-"
layar.Text = "" End Sub Private Sub
klikpersen_Click(sender As Object, e As EventArgs) Handles
klikpersen.Click If angka
= "0" Then
angka = Val(layar.Text) Else
angka = angka / 100 End If
operasi = "%"
layar.Text = "" End Sub Private Sub
klikkali_Click(sender As Object, e As EventArgs) Handles
klikkali.Click If angka
= "0" Then
angka = Val(layar.Text) Else
angka = angka * Val(layar.Text) End If
operasi = "x"
layar.Text = "" End Sub Private Sub
klikbagi_Click(sender As Object, e As EventArgs) Handles
klikbagi.Click If angka
= "0" Then
angka = Val(layar.Text) Else
angka = angka / Val(layar.Text) End If
operasi = "/"
layar.Text = "" End Sub Private Sub
klikpangkat_Click(sender As Object, e As EventArgs) Handles
klikpangkat.Click If angka
= "0" Then
angka = Val(layar.Text) Else
angka = angka ^ (1 / 2) End If
operasi = "^/"
layar.Text = "" End Sub Private Sub
klikcos_Click(sender As Object, e As EventArgs) Handles
klikcos.Click
layar.Text = Math.Cos(layar.Text * (Phi /
180)) End Sub Private Sub
kliksin_Click(sender As Object, e As EventArgs) Handles
kliksin.Click
layar.Text = Math.Sin(layar.Text * (Phi /
180)) End Sub Private Sub
kliktan_Click(sender As Object, e As EventArgs) Handles
kliktan.Click
layar.Text = Math.Tan(layar.Text * (Phi / 180)) End Sub Private Sub
kliklog_Click(sender As Object, e As EventArgs) Handles
kliklog.Click
layar.Text = Math.Log(layar.Text) End Sub Private Sub
klikhasil_Click(sender As Object, e As EventArgs) Handles
klikhasil.Click Select Case
operasi
Case "+"
hasil = angka + Val(layar.Text)
layar.Text = hasil
Case "-"
hasil = angka - Val(layar.Text)
layar.Text = hasil
Case "%" hasil = angka / 100
layar.Text = hasil
Case "x"
hasil = angka * Val(layar.Text)
layar.Text = hasil
Case "/"
hasil = angka / Val(layar.Text)
layar.Text = hasil
Case "^"
hasil = angka ^ Val(layar.Text)
layar.Text = hasil
Case "^/"
hasil = angka ^ 0.5
layar.Text = hasil End Select End Sub Private Sub
klikhapus_Click(sender As Object, e As EventArgs) Handles
klikhapus.Click If
layar.Text.Length <> 0 Then
layar.Text = layar.Text.Remove(layar.TextLength - 1, 1) End If End Sub Private Sub
klikclear_Click(sender As Object, e As EventArgs) Handles
klikclear.Click
layar.Text = "0"
angka = 0
hasil = 0
operasi = "" End Sub Private Sub
klikexit_Click(sender As Object, e As EventArgs) Handles
klikexit.Click End End Sub Private Sub
kalku_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class |
Gambar Hasil Tugas
Praktikum 1:
Langkah Tugas Praktikum 2
Untuk properties dari
masing-masing object, saya contohkan seperti dibawah ini, dengan letak
masing-masing object disesuaikan dengan gambar diatas.
Form (Name) : Form1 Text
: Menghitung Luas |
Textbox1 (Name)
: txtJari TextAlign : Left Text : <kosongkan> |
Textbox2 (Name)
: txtTinggi TextAlign : Left Text
: <kosongkan> |
Textbox1 (Name)
: txtLuas TextAlign : Left Text
: <kosongkan> |
Textbox4 (Name)
: txtVolume TextAlign : Left Text
: <kosongkan> |
Button1 (Name)
: btnProses Text
: Proses |
Button2 (Name)
: btnReset Text
: Reset |
Button3 (Name)
: btnKeluar Text
: Keluar |
Label1 (Name)
: Label1 Text
: Lingkaran Jari-jari |
Label2 (Name)
: Label2 Text
: Tinggi Tabung |
Label3 (Name)
: Label3 Text
: Luas Alas |
Label4 (Name)
: Label4 Text
: Volume |
Label5 (Name)
: Label5 Text
: Menghitung Luas Font
Size : 14 |
|
Berikutnya, Anda tinggal membuat coding dari kalkulator
tersebut. Jika Anda mengikuti semua setting properties seperti diatas, maka
codingnya saya contohkan seperti ini :
Public Class Form1 Dim r As Double Dim t As Double Dim luas As Double Dim
volume As Double Const phi As Double =
3.14 Private Sub
btnKeluar_Click(sender As Object, e As EventArgs) Handles
btnKeluar.Click If
MsgBox("Silakan Pilih 'Ya' Jika Anda Akan Keluar", MsgBoxStyle.YesNo,
"Pilihan!") = MsgBoxResult.Yes Then
Me.Close() Else
MsgBox("Batal Keluar", MsgBoxStyle.OkOnly,
"Pilihan!") End If End Sub Private Sub
btnProses_Click(sender As Object, e As EventArgs) Handles
btnProses.Click r =
Val(txtJari.Text) t =
Val(txtTinggi.Text) luas
= phi * (r ^ 2)
txtLuas.Text = luas
volume = phi * (r ^ 2) * t
txtVolume.Text = volume End Sub Private Sub
btnReset_Click(sender As Object, e As EventArgs) Handles
btnReset.Click
txtJari.Text = ""
txtTinggi.Text = ""
txtLuas.Text = ""
txtVolume.Text = "" End Sub End Class |
Gambar Hasil Tugas
Praktikum 2 :
Langkah
Tugas Praktikum 3
Untuk properties dari
masing-masing object, saya contohkan seperti
dibawah ini, dengan letak masing-masing object disesuaikan dengan gambar
diatas.
Form1:
Form (Name) : Form1 Text
: Form1 |
Textbox1 (Name)
: Text1 TextAlign : Left Text
: <kosongkan> TabIndex
: 0 |
Textbox2 (Name)
: Text2 TextAlign : Left Text
: <kosongkan> TabIndex
: 1 |
Textbox3 (Name)
: Text3 TextAlign : Left Text
: <kosongkan> TabIndex
: 2 |
Textbox4 (Name)
: Text4 TextAlign : Left Text
: <kosongkan> TabIndex
: 5 |
ComboBox1 (Name)
: Combo1 Text
: <kosongkan> TabIndex
: 3 |
ComboBox2 (Name)
: Combo2 Text
: <kosongkan> TabIndex
: 4 |
Button1 (Name)
: btn1 Text
: Baru TabIndex
: 6 |
Button2 (Name)
: btn2 Text
: Simpan TabIndex
: 7 |
Button3 (Name)
: btn3 Text
: Cetak TabIndex
: 8 |
Button4 (Name)
: btn4 Text
: Exit TabIndex
: 9 |
Label1 (Name)
: Label1 Text
: Daftar Nama Font
Size : 14 Bold TabIndex
: 10 |
Label2 (Name)
: Label2 Text
: No Urut Mahasiswa TabIndex
: 11 |
Label3 (Name)
: Label3 Text
: NIM TabIndex
: 12 |
Label4 (Name)
: Label4 Text
: Nama Mahasiswa TabIndex
: 13 |
Label5 (Name)
: Label5 Text
: Jurusan TabIndex
: 14 |
Label6 (Name)
: Label6 Text
: Jenjang TabIndex
: 15 |
Label7 (Name)
: Label7 Text
: Alamat TabIndex
: 16 |
Panel1 (Name)
: Panel1 Text
: Biodata TabIndex
: 17 |
|
Form2:
ListBox (Name)
: List1 |
Button1 (Name)
: btn2 Text
: Kembali |
Berikutnya, Anda tinggal membuat coding dari kalkulator
tersebut. Jika Anda mengikuti semua setting properties seperti diatas, maka
codingnya saya contohkan seperti ini :
Form1
Public Class Form1 Dim
NIM(99), Nama(99), jur(99), jen(99), alamat(99) As String Dim i,
jml As Integer Private Sub
Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Combo1.Items.Add("Teknik Informatika")
Combo1.Items.Add("PGSD") Combo1.Items.Add("Pendidikan
Ekonomi")
Combo1.Items.Add("Teknik Sipil")
Combo1.Items.Add("Teknik Lingkungan")
Combo1.Items.Add("Farmasi Kesehatan")
Combo1.Items.Add("Analisa Kesehatan")
Combo2.Items.Add("S1")
Combo2.Items.Add("D3") End Sub Private Sub
btn1_Click(sender As Object, e As EventArgs) Handles
btn1.Click
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Combo1.Items.Clear()
Combo1.Items.Add("Teknik Informatika")
Combo1.Items.Add("PGSD")
Combo1.Items.Add("Pendidikan Ekonomi")
Combo1.Items.Add("Teknik Sipil")
Combo1.Items.Add("Teknik Lingkungan")
Combo1.Items.Add("Farmasi Kesehatan")
Combo1.Items.Add("Analisa Kesehatan")
Combo2.Items.Clear()
Combo2.Items.Add("S1")
Combo2.Items.Add("D3")
Form2.List1.Items.Clear()
Text2.Focus() End Sub Private Sub
btn2_Click(sender As Object, e As EventArgs) Handles
btn2.Click jml
= Int(Text1.Text)
NIM(jml) = Text2.Text
Nama(jml) = Text3.Text
jur(jml) = Combo1.Text
jen(jml) = Combo2.Text
alamat(jml) = Text4.Text jml
= jml + 1
Text1.Text = jml
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Combo1.Text = ""
Combo2.Text = ""
Text2.Focus() End Sub Private Sub
btn3_Click(sender As Object, e As EventArgs) Handles
btn3.Click
Form2.List1.Items.Clear() Dim i As Integer For i = 1
To jml - 1
With Form2.List1
.Items.Add("Mahasiswa ke " &
i)
.Items.Add("NIM
: " & NIM(i))
.Items.Add("Nama
: " & Nama(i))
.Items.Add("Jurusan : " &
jur(i))
.Items.Add("Jenjang : " &
jen(i)) .Items.Add("Alamat : " & alamat(i))
.Items.Add("------------------------------------------------------------------------------")
End With Next Form2.Show() End Sub Private Sub
btn4_Click(sender As Object, e As EventArgs) Handles
btn4.Click End End Sub End Class |
Form2
Public Class Form2 Private Sub
btn2_Click(sender As Object, e As EventArgs) Handles
btn2.Click Me.Close() End Sub End Class |
Gambar Hasil Tugas
Praktikum 3 :
Modul VB NET
Modul PRAKTIKUM VB
Modul PRAKTIKUM VB.NET
0 Komentar
Berkomentar dengan bijak