· 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_alasAB
[dikosongkan]
|
TextBox2
|
Name
Text
|
txt_AC_AB
[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 = AB
|
Label3
|
Caption
|
AC = BC
|
Label4
|
Caption
|
Keliling
|
Label5
|
Caption
|
Luas
|
CommandButton1
|
Name
Caption
|
cmd_hitung
&Hitung
|
CommandButton2
|
Name
Caption
|
cmd_exit
E&xit
|
Form1
|
Name
Caption
|
Frm_SegitigaSamaKaki
Program untuk
Mencari Keliling dan Luas Segitiga Sama Kaki
|
· Klik menu View
=> Code, lalu kode program di
bawah ini :
Dim AD As Integer
Private Sub
cmd_exit_Click()
End
End Sub
Private Sub
cmd_hitung_Click()
On Error Resume
Next
If
Me.txt_alasAB.Text = "" Or Me.txt_AC_AB.Text = "" Then
MsgBox "Data masih ada yang kosong,
harap diisi terlebih dahulu!", vbInformation + vbOKOnly, "Data
Kosong"
Else
AD = Val(Me.txt_alasAB.Text) / 2
Me.lbl_tinggi.Caption =
Format((Sqr((Val(Me.txt_alasAB.Text) ^ 2) - (AD ^ 2))),
"###,###.###")
Me.lbl_keliling.Caption =
(Val(Me.txt_alasAB.Text) + Val(Me.txt_AC_AB.Text) + Val(Me.txt_AC_AB.Text))
Me.lbl_luas.Caption =
Format(((Val(Me.txt_alasAB.Text) * Me.lbl_tinggi.Caption) / 2),
"###,###.###")
Me.cmd_exit.SetFocus
End If
End Sub
Private Sub
Form_Load()
Me.txt_AC_AB.Enabled
= False
Me.cmd_hitung.Enabled
= False
End Sub
Private Sub
txt_AC_AB_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_AC_AB.Text = "" Then
MsgBox "Data tidak boleh
kosong", vbInformation + vbOKOnly, "Data Kosong"
Else
Me.cmd_hitung.Enabled = True
Me.cmd_hitung.SetFocus
End If
End If
End Sub
Private Sub
txt_alasAB_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_alasAB.Text = "" Then
MsgBox "Data tidak boleh
kosong", vbInformation + vbOKOnly, "Data Kosong"
Else
Me.txt_AC_AB.Enabled = True
Me.txt_AC_AB.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 !