Program Perhitungan Rumus Phytagoras Dengan Menggunakan Bahasa Pemograman Microsoft Visual Basic 6
Program Perhitungan Rumus Phytagoras Dengan Menggunakan Bahasa Pemograman Microsoft Visual Basic 6
0
Rumus Phytagoras atau biasa disebut dengan Rumus abcdigunakan untuk mencari panjang sisi - sisi segitiga siku - siku. Rumus Phyatgoras c2 = a2 + b2 a2 = c2 - b2 b2 = c2 - a2 :
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 Option1 Option2 Option3 TextBox1 TextBox2 TextBox2 Properties Caption Caption Caption Name Text Name Text Name Text Name Caption Appearance Border Style Caption Pengaturan Hitung nilai a Hitung nilai b Hitung nilai c txt_A [dikosongkan] txt_B [dikosongkan] txt_C [dikosongkan] lbl_jawaban [dikosongkan] 0 - Flat 1 - Fixed Single Sisi a (AB)
Label1 Label2
Sisi b (BC) Sisi c (AC) cmd_hitung &Hitung cmd_exit E&xit Frm_Phytagoras Rumus Phytagoras
: Untuk jenis, ukuran dan warna Font serta warna Form sesuaikan dengan selera anda. Nilai Left dan Top objek label_a, label_b, label_c, txt_A,txt_B dan txt_C sesuaikan dengan nilai masing - masing objek pada Properties Klik menu View => Code, lalu kode program di bawah ini :
Dim A, B, C As Integer Private Sub cmd_exit_Click() End End Sub Private Sub cmd_hitung_Click() If Me.Option1.Value = True Then B = Me.txt_B.Text C = Me.txt_C.Text Me.lbl_jawaban.Caption = Format(Sqr((C ^ 2) - (B ^ 2)), "###,###.###") ElseIf Me.Option2.Value = True Then A = Me.txt_A.Text C = Me.txt_C.Text Me.lbl_jawaban.Caption = Format(Sqr((C ^ 2) - (A ^ 2)), "###,###.###") ElseIf Me.Option3.Value = True Then A = Me.txt_A.Text B = Me.txt_B.Text Me.lbl_jawaban.Caption = Format(Sqr((A ^ 2) + (B ^ 2)), "###,###.###") End If Me.cmd_hitung.Enabled = False End Sub Private Sub Form_Load() Me.cmd_hitung.Enabled = False End Sub Private Sub Option1_Click() Me.label_a.Left = 120 Me.label_a.Top = 1200 Me.label_b.Left = 120 Me.label_b.Top = 240 Me.label_c.Left = 120
Me.label_c.Top = 720 Me.txt_A.Left = 1200 Me.txt_A.Top = 1200 Me.txt_B.Left = 1200 Me.txt_B.Top = 240 Me.txt_C.Left = 1200 Me.txt_C.Top = 720 Me.txt_A.Text = "" Me.txt_B.Text = "" Me.txt_C.Text = "" Me.txt_A.Visible = False Me.txt_B.Visible = True Me.txt_C.Visible = True Me.lbl_jawaban.Visible = True Me.lbl_jawaban.Caption = "" Me.txt_A.Enabled = False Me.txt_B.Enabled = True Me.txt_B.SetFocus Me.txt_C.Enabled = False End Sub Private Sub Option2_Click() 'nilai Left dan Top objek label_a, label_b, label_c, txt_A,txt_B dan txt_C 'sesuaikan dengan nilai masing - masing objek pada Properties Me.label_a.Left = 120 Me.label_a.Top = 240 Me.label_b.Left = 120 Me.label_b.Top = 1200 Me.label_c.Left = 120 Me.label_c.Top = 720 Me.txt_A.Left = 1200 Me.txt_A.Top = 240 Me.txt_B.Left = 1200 Me.txt_B.Top = 1200 Me.txt_C.Left = 1200 Me.txt_C.Top = 720 Me.txt_A.Text = "" Me.txt_B.Text = "" Me.txt_C.Text = "" Me.txt_A.Visible = True Me.txt_B.Visible = False Me.txt_C.Visible = True Me.lbl_jawaban.Visible = True Me.lbl_jawaban.Caption = "" Me.txt_A.Enabled = True
Me.txt_A.SetFocus Me.txt_B.Enabled = False Me.txt_C.Enabled = False End Sub Private Sub Option3_Click() Me.label_a.Left = 120 Me.label_a.Top = 240 Me.label_b.Left = 120 Me.label_b.Top = 720 Me.label_c.Left = 120 Me.label_c.Top = 1200 Me.txt_A.Left = 1200 Me.txt_A.Top = 240 Me.txt_B.Left = 1200 Me.txt_B.Top = 720 Me.txt_C.Left = 1200 Me.txt_C.Top = 1200 Me.txt_A.Text = "" Me.txt_B.Text = "" Me.txt_C.Text = "" Me.txt_A.Visible = True Me.txt_B.Visible = True Me.txt_C.Visible = False Me.lbl_jawaban.Visible = True Me.lbl_jawaban.Caption = "" Me.txt_A.Enabled = True Me.txt_A.SetFocus Me.txt_B.Enabled = False Me.txt_C.Enabled = False End Sub Private Sub txt_A_KeyPress(KeyAscii As Integer) Me.txt_A.MaxLength = 2 If KeyAscii = 13 Then If Me.txt_A.Text = "" Then MsgBox "Data tidak boleh kosong", vbInformation + vbOKOnly, "Data Kosong" Else If Me.Option2.Value = True Then Me.txt_C.Enabled = True Me.txt_C.SetFocus ElseIf Me.Option3.Value = True Then Me.txt_B.Enabled = True Me.txt_B.SetFocus End If End If End If End Sub Private Sub txt_B_KeyPress(KeyAscii As Integer)
Me.txt_B.MaxLength = 2 If KeyAscii = 13 Then If Me.txt_B.Text = "" Then MsgBox "Data tidak boleh kosong", vbInformation + vbOKOnly, "Data Kosong" Else If Me.Option3.Value = True Then If Val(Me.txt_B.Text) <= Val(Me.txt_A.Text) Then MsgBox "Data Salah, nilai B harus lebih besar dari nilai A", vbInformation + vbOKOnly, "Data Kosong" Me.txt_B.Text = "" Else Me.cmd_hitung.Enabled = True Me.cmd_hitung.SetFocus End If ElseIf Me.Option1.Value = True Then Me.txt_C.Enabled = True Me.txt_C.SetFocus End If End If End If End Sub Private Sub txt_C_KeyPress(KeyAscii As Integer) Me.txt_C.MaxLength = 2 If KeyAscii = 13 Then If Me.txt_C.Text = "" Then MsgBox "Data tidak boleh kosong", vbInformation vbOKOnly, "Data Kosong" Else If Me.Option1.Value = True Then If Val(Me.txt_C.Text) <= Val(Me.txt_B.Text) MsgBox "Data Salah, nilai C harus lebih dari nilai B", vbInformation + vbOKOnly, "Data Kosong" Me.txt_C.Text = "" Else Me.cmd_hitung.Enabled = True Me.cmd_hitung.SetFocus End If ElseIf Me.Option2.Value = True Then If Val(Me.txt_C.Text) <= Val(Me.txt_A.Text) MsgBox "Data Salah, nilai C harus lebih dari nilai A", vbInformation + vbOKOnly, "Data Kosong" Me.txt_C.Text = "" Else Me.cmd_hitung.Enabled = True Me.cmd_hitung.SetFocus End If End If End If End If
Then besar
Then besar
End Sub Jalankan Program dengan cara menekan tombol F5 pada keyboard atau pilih menu Run => Start Hasilnya ketika program dijalankan :
Gbr 2