Minggu, 22 Desember 2013

Membuat Aplikasi “Calculator” dengan Visual Basic 6.0

Calculator VB6

Jika sebelumnya saya sudah membuat aplikasi Simple Calculator yang terbatas hanya dengan dua buah masukan maka sekarang saya membuat aplikasi Calculator yang menyerupai bentuk aslinya dan kelebihan aplikasi ini dapat menerima masukan lebih banyak dari pada aplikasi sebelumnya. Tetapi aplikasi ini masih jauh dari sempurna. Akan tetapi cukup lumayan kinerjanya. Posting selanjutnya saya akan mengadaptasi aplikasi ini kedalam Visual Basic.NET. (Sumber: Here)

 

1. Jalankan aplikasi Visual Basic 6.0

2. Pada jendela “New Project” pilih “Standard EXE” kemudian tekan tombol “Open”

3. Berikut setingan kontrol properti yang terdapat pada aplikasi ini

Object Name Properties Setting
Form Form1 Border Style 1 - Fixed Single
    Caption Calculator
    Font Tahoma; 10pt
    Start Up Position 2 - Center Screen
Text Box txtDisplay Alignment 1 – Right Justify
    Enabled

False

    Font Tahoma; 18pt
Command Button cmdOne Caption 1
Command Button cmdTwo Caption 2
Command Button cmdThree Caption 3
Command Button cmdFour Caption 4
Command Button cmdFive Caption 5
Command Button cmdSix Caption 6
Command Button cmdSeven Caption 7
Command Button cmdEight Caption 8
Command Button cmdNine Caption 9
Command Button cmdZero Caption 0
Command Button cmdClear Caption C
Command Button cmdAdd Caption +
Command Button cmdSubtract Caption -
Command Button cmdMultiple Caption *
Command Button cmdDevide Caption /
Command Button cmdResult Caption =

4. Berikut event code program

Dim PointAdd As Integer
Dim PointSubtract As Integer
Dim PointMultiple As Integer
Dim PointDevide As Double
Dim Result As Integer
Dim Coice As String

Private Sub cmdOne_Click()
txtDisplay.Text = txtDisplay.Text + cmdOne.Caption
End Sub

Private Sub cmdZero_Click()
txtDisplay.Text = txtDisplay.Text + cmdZero.Caption
End Sub

Private Sub cmdClear_Click()
txtDisplay.Text = ""
End Sub

Private Sub cmdSubtract_Click()
PointSubtract = Val(txtDisplay.Text)
txtDisplay.Text = ""
Coice = "Subtract"
End Sub

Private Sub cmdAdd_Click()
PointAdd = Val(txtDisplay.Text)
txtDisplay.Text = ""
Coice = "Add"
End Sub

Private Sub cmdDevide_Click()
PointDevide = Val(txtDisplay.Text)
txtDisplay.Text = ""
Coice = "Devide"
End Sub

Private Sub cmdMultiple_Click()
PointMultiple = Val(txtDisplay.Text)
txtDisplay.Text = ""
Coice = "Multiple"
End Sub

Private Sub cmdResult_Click()
Select Case Coice
Case "Add"
Result = PointAdd + Val(txtDisplay.Text)
txtDisplay.Text = Str(Result)
Case "Subtract"
Result = PointSubtract - Val(txtDisplay.Text)
txtDisplay.Text = Str(Result)
Case "Multiple"
Result = PointMultiple * Val(txtDisplay.Text)
txtDisplay.Text = Str(Result)
Case "Devide"
Result = PointDevide / Val(txtDisplay.Text)
txtDisplay.Text = Str(Result)
End Select
End Sub

Private Sub cmdTwo_Click()
txtDisplay.Text = txtDisplay.Text + cmdTwo.Caption
End Sub

Private Sub cmdThree_Click()
txtDisplay.Text = txtDisplay.Text + cmdThree.Caption
End Sub

Private Sub cmdFour_Click()
txtDisplay.Text = txtDisplay.Text + cmdFour.Caption
End Sub

Private Sub cmdFive_Click()
txtDisplay.Text = txtDisplay.Text + cmdFive.Caption
End Sub

Private Sub cmdSix_Click()
txtDisplay.Text = txtDisplay.Text + cmdSix.Caption
End Sub

Private Sub cmdSeven_Click()
txtDisplay.Text = txtDisplay.Text + cmdSeven.Caption
End Sub

Private Sub cmdEight_Click()
txtDisplay.Text = txtDisplay.Text + cmdEight.Caption
End Sub

Private Sub cmdNine_Click()
txtDisplay.Text = txtDisplay.Text + cmdNine.Caption
End Sub

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda