· 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_A
[dikosongkan]
|
TextBox1
|
Name
Text
|
txt_B
[dikosongkan]
|
TextBox1
|
Name
Text
|
txt_C
[dikosongkan]
|
Label1
|
Name
Caption
Appearance
Border Style
|
lbl_S
[dikosongkan]
0 - Flat
1 - Fixed Single
|
Label2
|
Name
Caption
Appearance
Border Style
|
lbl_keliling
[dikosongkan]
0 - Flat
1 - Fixed Single
|
Label3
|
Name
Caption
Appearance
Border Style
|
lbl_luas
[dikosongkan]
0 - Flat
1 - Fixed Single
|
Label6
|
Caption
|
a
|
Label9
|
Caption
|
b
|
Label10
|
Caption
|
c
|
Label11
|
Caption
|
S
|
Label12
|
Caption
|
K
|
Label13
|
Caption
|
L
|
CommandButton1
|
Name
Caption
|
cmd_hitung
&Hitung
|
CommandButton2
|
Name
Caption
|
cmd_exit
E&xit
|
Form1
|
Name
Caption
|
Frm_SegitigaSembarang
Program untuk
Mencari nilai S, Luas dan Keliling Segitiga Sembarang
|
· Klik menu View
=> Code, lalu kode program di
bawah ini :
Private Sub
cmd_exit_Click()
End
End Sub
Private Sub
cmd_hitung_Click()
Me.lbl_keliling.Caption =
((Val(Me.txt_A.Text) + Val(Me.txt_B.Text) + Val(Me.txt_C.Text)))
Me.lbl_S.Caption = (0.5 *
Val(Me.lbl_keliling.Caption))
Me.lbl_luas.Caption =
Format(Sqr(Me.lbl_S.Caption * ((Val(Me.lbl_S.Caption) - Val(Me.txt_A.Text)) *
(Val(Me.lbl_S.Caption) - Val(Me.txt_B.Text)) * (Val(Me.lbl_S.Caption) -
Val(Me.txt_C.Text)))), "###,###.#0")
Me.cmd_exit.SetFocus
End Sub
Private Sub
Form_Load()
Me.txt_A.Enabled =
True
Me.txt_B.Enabled =
False
Me.txt_C.Enabled =
False
Me.cmd_hitung.Enabled
= False
End Sub
Private Sub
txt_A_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_A.Text = "" Then
MsgBox "Data tidak boleh
kosong", vbInformation + vbOKOnly, "Data Kosong"
Else
Me.txt_B.Enabled = True
Me.txt_B.Text = ""
Me.txt_B.SetFocus
End If
End If
End Sub
Private Sub
txt_B_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_B.Text = "" Then
MsgBox "Data tidak boleh
kosong", vbInformation + vbOKOnly, "Data Kosong"
Else
Me.txt_C.Enabled = True
Me.txt_C.Text = ""
Me.txt_C.SetFocus
End If
End If
End Sub
Private Sub
txt_C_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_C.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
· 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 !