Tutorial
Program Aplikasi Bangun 2 Dimensi dan 3 Dimensi
Visual Basic merupakan bahasa
pemrograman yang dapat digunakan untuk membuat suatu program sederhana. Berikut
adalah contoh langkah-langkah penggunaan visual basic 2010 dalam membuat program
aplikasi bangun 2 dimensi dan 3 dimensi.
Langkah-Langkah:
1. Membuka
Aplikasi Visual Basic 2010
2. Klik Windows Form Application untuk
memunculkan tampilan seperti berikut
3. Klik menu bar-view-other
windows-tollbox untuk memunculkan toolbox yang akan digunakan
4. Membuat Form seperti di
bawah ini dengan menggunakan komponen toolbox di atas dan diberi nama dengan
mengganti text pada properties
Berikut
adalah komponen ToolBox yang digunakan dalam Form aplikasi bangun 2 dimensi dan
3 dimensi ini
Bangun
Ruang
No
|
Komponen
|
Properties
|
Keterangan
|
1.
|
Form
1
|
Name
text
|
Form
1
Aplikasi
2D & 3D
|
2.
|
Label
2
|
Name
text
|
Label
2
Selamat Datang di Aplikasi
Bangun 2 Dimensi dan 3 Dimensi
|
3.
|
Label
3
|
Name
text
|
Label
3
Silahkan
Pilih Bentukmu
|
4.
|
Radiobutton
1
|
Name
text
|
Radiobutton
1
Persegi
|
5.
|
Radiobutton
2
|
Name
text
|
Radiobutton
2
Persegi
Panjang
|
6.
|
Radiobutton
3
|
Name
text
|
Radiobutton
3
Kubus
|
7.
|
Radiobutton
4
|
Name
text
|
Radiobutton
4
Balok
|
8.
|
Button
1
|
Name
text
|
Button
1
Lanjut
|
9.
|
Form
2
|
Name
text
|
Form
2
Persegi
|
10.
|
Label
1
|
Name
text
|
Label
1
Sisi
|
11.
|
Label
2
|
Name
text
|
Label
2
Luas
|
12.
|
Textbox
1
|
Name
text
|
Textbox
1
|
13.
|
Textbox
2
|
Name
text
|
Textbox
2
|
14.
|
Textbox
3
|
Name
text
|
Textbox
3
|
15.
|
Picturebox
1
|
Name
text
|
Picturebox
1
|
16.
|
Button
3
|
Name
text
|
Button
3
Kembali
|
17.
|
Button
4
|
Name
text
|
Button
4
Reset
|
18.
|
Button
5
|
Name
text
|
Button
5
Cek
|
19.
|
Form
4
|
Name
text
|
Form
4
Kubus
|
20.
|
Label
1
|
Name
text
|
Label
1
Sisi
|
21.
|
Label
2
|
Name
text
|
Label
2
Volum
|
22.
|
Textbox
1
|
Name
text
|
Textbox
1
|
23.
|
Textbox
2
|
Name
text
|
Textbox
2
|
24.
|
Textbox
3
|
Name
text
|
Textbox
3
|
25.
|
Textbox
4
|
Name
text
|
Textbox
4
|
26.
|
Picturebox
1
|
Name
text
|
Picturebox
1
|
27.
|
Button
2
|
Name
text
|
Button
2
Kembalki
|
28.
|
Button
3
|
Name
text
|
Button
3
Cek
|
29.
|
Button
4
|
Name
text
|
Button
4
Reset
|
30.
|
Form
6
|
Name
text
|
Form
6
Persegi
Panjang
|
31.
|
Label
1
|
Name
text
|
Label
1
Lebar
|
32.
|
Label
2
|
Name
text
|
Label
2
Panjang
|
33.
|
Label
3
|
Name
text
|
Label
3
Luas
|
34.
|
Textbox
1
|
Name
text
|
Textbox
1
|
35.
|
Textbox
2
|
Name
text
|
Textbox
2
|
36.
|
Textbox
3
|
Name
text
|
Textbox
3
|
37.
|
Picturebox
1
|
Name
text
|
Picturebox
1
|
38.
|
Button
1
|
Name
text
|
Button
1
Cek
|
39.
|
Button
2
|
Name
text
|
Button
2
Reset
|
40.
|
Button
4
|
Name
text
|
Button
4
Kembali
|
41.
|
Form
8
|
Name
text
|
Form
8
Balok
|
42.
|
Label
1
|
Name
text
|
Label
1
Lebar
|
43.
|
Label
2
|
Name
text
|
Label
2
Panjang
|
44.
|
Label
3
|
Name
text
|
Label
3
Volum
|
45.
|
Label
4
|
Name
text
|
Label
4
Tinggi
|
46.
|
Textbox
1
|
Name
text
|
Textbox
1
|
47.
|
Textbox
2
|
Name
text
|
Textbox
2
|
48.
|
Textbox
3
|
Name
text
|
Textbox
3
|
49.
|
Textbox
4
|
Name
text
|
Textbox
4
|
50.
|
Picturebox
1
|
Name
text
|
Picturebox
1
|
51.
|
Button
1
|
Name
text
|
Button
1
Cek
|
52.
|
Button
2
|
Name
text
|
Button
2
Reset
|
53.
|
Button
4
|
Name
text
|
Button
4
Kembali
|
Agar program
berjalan, buatlah listing sebagai berikut:
1. Double click pada design form
2. Listing pada Form1 yaitu, berbagai bentuk bangun
ruang yang dapat kita pilih menggunakan RadioButton
Public Class
Form1
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If
RadioButton1.Checked Then
Form2.Show()
Me.Hide()
End If
If
RadioButton2.Checked Then
Form6.Show()
Me.Hide()
End If
If
RadioButton3.Checked Then
Form4.Show()
Me.Hide()
End If
If
RadioButton4.Checked Then
Form8.Show()
Me.Hide()
End If
End Sub
Private Sub
RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
RadioButton1.CheckedChanged
End Sub
End Class
3.
Listing pada Form2 yaitu, form persegi
yang dapat kita ubah ukurannya dengan menginput angka pada TextBox3 yang akan
sama dengan textBox1
Public Class
Form2
Dim Luas As
Integer
Dim sisi As
Integer
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub
TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
TextBox3.Text = TextBox1.Text
End Sub
Private Sub
Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
PictureBox1.Visible = False
End Sub
Private Sub
Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
Luas = sisi * sisi
TextBox2.Text = Luas
TextBox2.Text = TextBox1.Text *
TextBox3.Text
PictureBox1.Visible = True
PictureBox1.Width = TextBox1.Text * 2
PictureBox1.Height = TextBox3.Text * 2
End Sub
Sebagai
tambahan, agar TextBox hanya dapat diinput oleh angka, ketikkan listing berikut
Private Sub
TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox2_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox3_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
PictureBox1.Click
End Sub
End Class
4.
Listing pada Form4 yaitu, form kubus
yang dapat kita ubah ukurannya dengan menginput angka pada TextBox1 yang akan
sama dengan TextBox3 dan textBox4
Public Class
Form4
Dim volum As
Integer
Dim sisi As
Integer
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub
TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
TextBox3.Text = TextBox1.Text
TextBox4.Text = TextBox1.Text
End Sub
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
volum = sisi * sisi * sisi
TextBox2.Text = volum
TextBox2.Text = TextBox1.Text *
TextBox3.Text * TextBox4.Text
PictureBox1.Visible = True
PictureBox1.Width = TextBox1.Text * 2
PictureBox1.Height = TextBox3.Text * 2
PictureBox1.Height = TextBox4.Text * 2
End Sub
Private Sub
Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
PictureBox1.Visible = False
End Sub
Private Sub
TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox2_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox3_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox4_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox3.TextChanged
End Sub
Private Sub
TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox4.TextChanged
End Sub
End Class
5.
Listing pada Form6 yaitu, form persegi
panjang yang dapat diubah ukurannya dengan menginput angka pada TextBox2
sebagai panjang dan textbox3 sebagai lebar
Public Class
Form6
Dim luas As
Integer
Dim sisi As
Integer
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
luas = sisi * sisi
TextBox1.Text = luas
TextBox1.Text = TextBox2.Text *
TextBox3.Text
PictureBox1.Visible = True
PictureBox1.Width = TextBox1.Text * 2
PictureBox1.Height = TextBox3.Text * 2
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
PictureBox1.Visible = False
End Sub
Private Sub
Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub
TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox2.TextChanged
End Sub
Private Sub
TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox2_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox3_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox3.TextChanged
End Sub
End Class
6.
Listing pada Form8 yaitu, form balok
yang dapat diubah ukurannya dengan menginput angka pada TextBox1 sebagai
panjang, textBox3 sebagai lebar, dan textBox4 sebagai tinggi
Public Class
Form8
Dim volum As
Integer
Dim sisi As
Integer
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
volum = sisi * sisi * sisi
TextBox2.Text = volum
TextBox2.Text = TextBox1.Text *
TextBox3.Text * TextBox4.Text
PictureBox1.Visible = True
PictureBox1.Width = TextBox1.Text * 2
PictureBox1.Height = TextBox3.Text * 2
PictureBox1.Height = TextBox4.Text * 2
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
PictureBox1.Visible = False
End Sub
Private Sub
Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub
TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
End Sub
Private Sub
TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox2_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox3_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox4_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
If
Asc(e.KeyChar) >= 48 And Asc(e.KeyChar)
<= 57 Then
e.Handled = False
ElseIf
Asc(e.KeyChar) = 43 Or Asc(e.KeyChar) = 95 Or Asc(e.KeyChar) = 45 Or
Asc(e.KeyChar) = 44 Or Asc(e.KeyChar) = 46 Then
e.Handled = False
ElseIf
e.KeyChar = vbBack Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub
TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox3.TextChanged
End Sub
Private Sub
TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox4.TextChanged
End Sub
End Class
Konsep
Program Aplikasi Bangun 2 Dimensi dan 3 Dimensi
Deskripsi
Program
aplikasi bangun 2 dimensi dan 3 dimensi ini dibuat dengan visual basic 2010
yang didalamnya terdapat berbagai jenis bangun 2 dimensi dam 3 dimensi seperti
persegi, persegi panjang, kubus, dan balok. Selain itu, ukuran dari
masing-masing bangun tersebut dapat diubah dengan menginput angka.
Tujuan
Tujuan
dibuatnya program aplikasi bangun 2 dimensi dan 3 dimensi ini adalah sebagai
latihan dan pengajaran untuk membuat aplikasi bangun 2 dimensi dan 3 dimensi
sederhana dari software visual basic 2010.
Manfaat
Manfaat
dari pembuatan aplikasi bangun 2 dimensi dan 3 dimensi sederhana ini agar murid
TK dapat mengetahui macam-macam bangun dan dapat mengubah ukurannya sesuka
hati.
Sasaran
user
Aplikasi
bangun 2 dimensi dan 3 dimensi ditujukan kepada guru TK