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_jarijari
[dikosongkan]
|
TextBox2
|
Name
Text
|
txt_tinggi
[dikosongkan]
|
Label1
|
Name
Caption
Appearance
Border Style
|
lbl_luas
[dikosongkan]
0 - Flat
1 - Fixed Single
|
Label2
|
Name
Caption
Appearance
Border Style
|
lbl_volume
[dikosongkan]
0 - Flat
1 - Fixed Single
|
Label3
|
Caption
|
Jari - Jari ( r )
|
Label3
|
Caption
|
Tinggai ( h )
|
Label4
|
Caption
|
Luas
|
Label5
|
Caption
|
Volume
|
CommandButton1
|
Name
Caption
|
cmd_exit
E&xit
|
Form1
|
Name
Caption
|
Frm_Kerucut
Program untuk menghitung
Volume dan Luas Kerucut
|
· Klik menu View
=> Code, lalu kode program di bawah
ini :
Const Pi =
3.14159265
Dim Sepertiga As
Double
Private Sub
cmd_exit_Click()
End
End Sub
Private Sub
Form_Load()
Me.txt_tinggi.Enabled
= False
End Sub
Private Sub
txt_jarijari_Change()
On Error Resume
Next
If
Me.txt_jarijari.Text = "" Then
Me.lbl_luas.Caption = ""
Me.lbl_volume.Caption = ""
Else
Sepertiga = Format((1 / 3),
"##0.##0")
Me.lbl_volume.Caption =
Format((Sepertiga * ((Pi * ((Val(Me.txt_jarijari.Text) ^ 2) *
(Val(Me.txt_tinggi.Text)))))), "###,###.##0")
Me.lbl_luas.Caption = Format((((Pi *
Val(Me.txt_jarijari.Text)) * (Sqr((Val(Me.txt_jarijari.Text) ^ 2) +
(Val(Me.txt_tinggi.Text) ^ 2)))) + (Pi * (Val(Me.txt_jarijari.Text) ^ 2))),
"###,###.##0")
End If
End Sub
Private Sub
txt_jarijari_KeyPress(KeyAscii As Integer)
If KeyAscii = 13
Then
If Me.txt_jarijari.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()
On Error Resume
Next
If
Me.txt_tinggi.Text = "" Then
Me.lbl_luas.Caption = ""
Me.lbl_volume.Caption = ""
Else
Sepertiga = Format((1 / 3),
"##0.##0")
Me.lbl_volume.Caption =
Format((Sepertiga * ((Pi * ((Val(Me.txt_jarijari.Text) ^ 2) *
(Val(Me.txt_tinggi.Text)))))), "###,###.##0")
Me.lbl_luas.Caption = Format((((Pi *
Val(Me.txt_jarijari.Text)) * (Sqr((Val(Me.txt_jarijari.Text) ^ 2) + (Val(Me.txt_tinggi.Text)
^ 2)))) + (Pi * (Val(Me.txt_jarijari.Text) ^ 2))), "###,###.##0")
End If
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
Sepertiga = Format((1 / 3),
"##0.##0")
Me.lbl_volume.Caption =
Format((Sepertiga * ((Pi * ((Val(Me.txt_jarijari.Text) ^ 2) *
(Val(Me.txt_tinggi.Text)))))), "###,###.##0")
Me.lbl_luas.Caption = Format((((Pi *
Val(Me.txt_jarijari.Text)) * (Sqr((Val(Me.txt_jarijari.Text) ^ 2) +
(Val(Me.txt_tinggi.Text) ^ 2)))) + (Pi * (Val(Me.txt_jarijari.Text) ^ 2))),
"###,###.##0")
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 !