·
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_alas
[dikosongkan]
|
TextBox2
|
Name
Text
|
txt_sisi_miring
[dikosongkan]
|
TextBox3
|
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
|
Caption
|
Alas
|
Label4
|
Caption
|
Sisi Miring
|
Label5
|
Caption
|
Tinggi (h)
|
Label6
|
Caption
|
Keliling
|
Label7
|
Caption
|
Luas
|
CommandButton1
|
Name
Caption
|
cmd_exit
E&xit
|
Form1
|
Name
Caption
|
Frm_JajaranGenjang
Program untuk
mencari Keliling dan Luas Jajaran Genjang
|
·
Klik menu View
=> Code, lalu kode program di
bawah ini :
Private Sub
cmd_exit_Click()
End
End Sub
Private Sub
Form_Load()
Me.txt_sisi_miring.Enabled
= False
Me.txt_tinggi.Enabled
= False
End Sub
Private Sub txt_alas_Change()
On Error Resume
Next
Me.lbl_keliling.Caption = ((2 *
Val(Me.txt_alas.Text)) + (2 * Val(Me.txt_sisi_miring.Text)))
Me.lbl_luas.Caption = Val(Me.txt_alas.Text)
* Val(Me.txt_tinggi.Text)
End Sub
Private Sub txt_alas_KeyPress(KeyAscii
As Integer)
If KeyAscii = 13
Then
If Me.txt_alas.Text = "" Then
MsgBox "Data tidak boleh
kosong", vbInformation + vbOKOnly, "Data Kosong"
Else
Me.txt_sisi_miring.Enabled = True
Me.txt_sisi_miring.SetFocus
End If
End If
End Sub
Private Sub
txt_sisi_miring_Change()
On Error Resume
Next
Me.lbl_keliling.Caption = ((2 *
Val(Me.txt_alas.Text)) + (2 * Val(Me.txt_sisi_miring.Text)))
Me.lbl_luas.Caption = Val(Me.txt_alas.Text)
* Val(Me.txt_tinggi.Text)
End Sub
Private Sub
txt_sisi_miring_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_sisi_miring.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_tinggi_Change()
Me.lbl_keliling.Caption = ((2 *
Val(Me.txt_alas.Text)) + (2 * Val(Me.txt_sisi_miring.Text)))
Me.lbl_luas.Caption = Val(Me.txt_alas.Text)
* Val(Me.txt_tinggi.Text)
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_alas.Text)) + (2 * Val(Me.txt_sisi_miring.Text)))
Me.lbl_luas.Caption = Val(Me.txt_alas.Text)
* Val(Me.txt_tinggi.Text)
Me.cmd_exit.SetFocus
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 !