Pages

Saturday, March 10, 2012

Membuat Program Aritmatika dengan VB

Membuat Program Aritmatika dengan VB

Program ini digunakan untuk membuat prosedur yaitu blok kode program yang berisi perintah-perintah untuk mengerjakan proses aritmatika tambah, kurang, bagi, kali.

Nama File              : Procedure
Nama Program       : Visual Basic
Input / Deklarasi    : label
                                 command
                                 caption 
                                 Prosedur Sub dan Prosedur Function
                                 Proses aritmatika tambah, kurang, bagi, kali


LISTING PROGRAM :

Private Sub Aktifkan(teks As String, warna As ColorConstants)
txtAngka1.Enabled = True
txtAngka2.Enabled = True
lblHasil.Caption = teks
lblHasil.BackColor = warna
cmdJumlah.Enabled = True
cmdKurang.Enabled = True
cmdKali.Enabled = True
cmdBagi.Enabled = True
cmdAktif.Enabled = False
End Sub

Private Sub NonAktifkan(teks As String, warna As ColorConstants)
txtAngka1.Enabled = False
txtAngka2.Enabled = False
lblHasil.Caption = teks
lblHasil.BackColor = warna
cmdJumlah.Enabled = False
cmdKurang.Enabled = False
cmdKali.Enabled = False
cmdBagi.Enabled = False
cmdAktif.Enabled = True
End Sub

Private Function JumlahAngka() As String
Dim angka1 As String, angka2 As String
Dim hasil As Single                                
angka1 = txtAngka1.Text
angka2 = txtAngka2.Text
If angka1 <> "" And angka2 <> "" Then
hasil = CSng(angka1) + CSng(angka2)
JumlahAngka = CStr(hasil)
End If
End Function

Private Function KurangAngka() As String
Dim angka3 As String, angka4 As String
Dim hasil2 As Single                              
angka3 = txtAngka1.Text
angka4 = txtAngka2.Text
If angka3 <> "" And angka4 <> "" Then
hasil2 = CSng(angka3) - CSng(angka4)
KurangAngka = CStr(hasil2)
End If
End Function

Private Function KaliAngka() As String
Dim angka5 As String, angka6 As String
Dim hasil3 As Single                              
angka5 = txtAngka1.Text
angka6 = txtAngka2.Text
If angka5 <> "" And angka6 <> "" Then
hasil3 = CSng(angka5) * CSng(angka6)
KaliAngka = CStr(hasil3)
End If
End Function

Private Function BagiAngka() As String
Dim angka7 As String, angka8 As String
Dim hasil4 As Single                              
angka7 = txtAngka1.Text
angka8 = txtAngka2.Text
If angka7 <> "" And angka8 <> "" Then
hasil4 = CSng(angka7) / CSng(angka8)
BagiAngka = CStr(hasil4)
End If
End Function

Private Sub cmdAktif_Click()
Call Aktifkan("Masukkan angka ke1 dan ke2", vbWhite)
End Sub

Private Sub cmdJumlah_Click()
Call NonAktifkan("", vbYellow)
lblHasil.Caption = JumlahAngka()
End Sub

Private Sub cmdKurang_Click()
Call NonAktifkan("", vbYellow)
lblHasil.Caption = KurangAngka()
End Sub

Private Sub cmdKali_Click()
Call NonAktifkan("", vbYellow)
lblHasil.Caption = KaliAngka()
End Sub

Private Sub cmdBagi_Click()
Call NonAktifkan("", vbYellow)
lblHasil.Caption = BagiAngka()
End Sub

Private Sub Form_Load()
Call NonAktifkan("Aktifkan TextBox && Tombol Jumlahkan", vbYellow)
End Sub

Properti
Setting
Nilai
Form1
Caption
Test Procedure

Name
frmTestProcedure
Label1
Caption
Angka Pertama
Label2
Caption
Angka Kedua
Text1
Text
(kosong)

Name
txtAngka1
Text2
Text
(kosong)

Name
txtAngka2
Command1
Caption
Aktifkan

Name
cmdAktifkan
Command2
Caption
Jumlahkan

Name
cmdJumlah
Command3
Caption
Kurangi

Name
cmdKurang
Command4
Caption
Kalikan

Name
cmdKali
Command5
Caption
Bagi

Name
cmdBagi


Output :












No comments:

Post a Comment