Langkah - langkah pembuatan program:
·
Buka proyek Standard EXE yang baru
·
Disain tampilan form seperti gambar berikut dengan menggunakan
objek Label dan TextBox dan CommandButton
Gbr 1
·
Atur Properties masing - masing kontrol seperti dibawah ini
:
Kontrol
|
Properties
|
Pengaturan
|
TextBox1
|
Name
Text
|
txt_panjang
[dikosongkan]
|
TextBox1
|
Name
Text
|
txt_lebar
[dikosongkan]
|
TextBox1
|
Name
Text
|
txt_tinggi
[dikosongkan]
|
Label1
|
Name
Caption
Appearance
Border Style
|
lbl_keliling
[dikosongkan]
0 - Flat
1 - Fixed Single
|
Label2
|
Name
Caption
Appearance
Border Style
|
lbl_luas
[dikosongkan]
0 - Flat
1 - Fixed Single
|
Label3
|
Name
Caption
Appearance
Border Style
|
lbl_volume
[dikosongkan]
0 - Flat
1 - Fixed Single
|
Label4
|
Caption
|
Panjang
|
Label5
|
Caption
|
Lebar
|
Label5
|
Caption
|
Tinggi
|
Label6
|
Caption
|
Keliling
|
Label7
|
Caption
|
Luas
|
Label5
|
Caption
|
Volume
|
CommandButton1
|
Name
Caption
|
cmd_exit
E&xit
|
Form1
|
Name
Caption
|
Frm_Balok
Program menghitung
Keliling, Luas dan Volume Balok
|
·
Klik menu View
=> Code, lalu kode program di
bawah ini :
Private Sub
cmd_exit_Click()
End
End Sub
Private Sub
Form_Load()
Me.txt_lebar.Enabled
= False
Me.txt_tinggi.Enabled
= False
End Sub
Private Sub
txt_lebar_Change()
On Error Resume
Next
Me.lbl_keliling.Caption = (2 *
Val(Me.txt_panjang.Text)) + (2 * Val(Me.txt_lebar.Text)) + (2 * Val(Me.txt_tinggi.Text))
& " cm"
Me.lbl_luas.Caption = (2 *
Val(Me.txt_panjang.Text) * Val(Me.txt_lebar.Text)) + (2 *
Val(Me.txt_panjang.Text) * Val(Me.txt_tinggi.Text)) + (2 *
Val(Me.txt_lebar.Text) * Val(Me.txt_tinggi.Text)) & " cm2"
Me.lbl_volume.Caption = Val(Me.txt_panjang.Text)
* Val(Me.txt_lebar.Text) * Val(Me.txt_tinggi.Text) & " cm3"
End Sub
Private Sub
txt_lebar_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_lebar.Text = "" Then
MsgBox "Data tidak boleh
kosong", vbInformation + vbOKOnly, "Data Kosong"
Else
Me.txt_tinggi.Enabled = True
Me.txt_tinggi.SetFocus
End If
End If
End Sub
Private Sub
txt_panjang_Change()
On Error Resume
Next
Me.lbl_keliling.Caption = (2 *
Val(Me.txt_panjang.Text)) + (2 * Val(Me.txt_lebar.Text)) + (2 *
Val(Me.txt_tinggi.Text)) & " cm"
Me.lbl_luas.Caption = (2 *
Val(Me.txt_panjang.Text) * Val(Me.txt_lebar.Text)) + (2 *
Val(Me.txt_panjang.Text) * Val(Me.txt_tinggi.Text)) + (2 *
Val(Me.txt_lebar.Text) * Val(Me.txt_tinggi.Text)) & " cm2"
Me.lbl_volume.Caption =
Val(Me.txt_panjang.Text) * Val(Me.txt_lebar.Text) * Val(Me.txt_tinggi.Text)
& " cm3"
End Sub
Private Sub
txt_panjang_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_panjang.Text = "" Then
MsgBox "Data tidak boleh
kosong", vbInformation + vbOKOnly, "Data Kosong"
Else
Me.txt_lebar.Enabled = True
Me.txt_lebar.SetFocus
End If
End If
End Sub
Private Sub
txt_tinggi_Change()
On Error Resume
Next
Me.lbl_keliling.Caption = (2 *
Val(Me.txt_panjang.Text)) + (2 * Val(Me.txt_lebar.Text)) + (2 *
Val(Me.txt_tinggi.Text)) & " cm"
Me.lbl_luas.Caption = (2 *
Val(Me.txt_panjang.Text) * Val(Me.txt_lebar.Text)) + (2 *
Val(Me.txt_panjang.Text) * Val(Me.txt_tinggi.Text)) + (2 *
Val(Me.txt_lebar.Text) * Val(Me.txt_tinggi.Text)) & " cm2"
Me.lbl_volume.Caption =
Val(Me.txt_panjang.Text) * Val(Me.txt_lebar.Text) * Val(Me.txt_tinggi.Text)
& " cm3"
End Sub
Private Sub
txt_tinggi_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_tinggi.Text = "" Then
MsgBox "Data tidak boleh
kosong", vbInformation + vbOKOnly, "Data Kosong"
Else
Me.lbl_keliling.Caption = (2 *
Val(Me.txt_panjang.Text)) + (2 * Val(Me.txt_lebar.Text)) + (2 *
Val(Me.txt_tinggi.Text)) & " cm"
Me.lbl_luas.Caption = (2 *
Val(Me.txt_panjang.Text) * Val(Me.txt_lebar.Text)) + (2 *
Val(Me.txt_panjang.Text) * Val(Me.txt_tinggi.Text)) + (2 *
Val(Me.txt_lebar.Text) * Val(Me.txt_tinggi.Text)) & " cm2"
Me.lbl_volume.Caption =
Val(Me.txt_panjang.Text) * Val(Me.txt_lebar.Text) * Val(Me.txt_tinggi.Text)
& " cm3"
End If
End If
End Sub
·
Jalankan Program dengan cara menekan tombol F5 pada keyboard
atau pilih menu Run => Start
·
Hasilnya ketika program dijalankan :
Gbr 2
Tidak ada komentar:
Posting Komentar
Pos kan komentar anda !