BUAT APLIKASI KALKULATOR

MENGGUNAKAN VISUAL BASIC 6.0

 

Pertama :

buatlah tampilan kalkulator seperti gambar di bawah :

vbKal

Kedua :

Copas Source Code berikut :

Dim oper1 As Double
Dim oper2 As Double
Dim pop As String
Dim result As Double
Dim op As String
Public act As Integer

Private Sub c_Click(Index As Integer)
display.Caption = 0
oper2 = 0
oper1 = 0
result = 0
op = "+"
End Sub

Private Sub c_LostFocus(Index As Integer)
display.Caption = ""
End Sub

Private Sub Command1_LostFocus()
display.Caption = ""
End Sub

Private Sub Command2_Click()

End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub dig_Click(Index As Integer)
display.Caption = display.Caption + dig(Index).Caption
End Sub

Private Sub div_Click(Index As Integer)
If op = "+" Then
oper1 = Val(display.Caption) + oper2
ElseIf op = "-" Then oper1 = oper2 - Val(display.Caption)
ElseIf op = "*" Then oper1 = oper2 * Val(display.Caption)

End If

If op = "/" Then
If Val(display.Caption) = 0 Then
MsgBox "Can't Divide by Zero!!"
Else
oper1 = oper2 / Val(display.Caption)
End If
End If

If op = "" Then oper1 = Val(display.Caption)

oper2 = oper1
op = "/"
pop = op
display.Caption = oper2

End Sub

Private Sub div_LostFocus(Index As Integer)
display.Caption = ""
End Sub

Private Sub eq_Click(Index As Integer)

If op = "+" Then
result = Val(display.Caption) + oper2
End If

If op = "-" Then
result = oper2 - Val(display.Caption)
End If

If op = "/" Then
If Val(display.Caption) = 0 Then
MsgBox "Can't Divide by Zero!!"
Else
result = oper2 / Val(display.Caption)
End If
End If

If op = "*" Then
result = oper2 * Val(display.Caption)
End If

display.Caption = result
op = "+"
oper1 = 0
oper2 = 0

End Sub

Private Sub Form_Load()
display.Caption = 0
oper2 = 0
oper1 = 0
result = 0
op = "+"
End Sub

Private Sub Form_Paint()
act = 1
display.Caption = 0
cmdClose.SetFocus
End Sub

Private Sub minus_Click(Index As Integer)

If op = "+" Then
oper1 = Val(display.Caption) + oper2
ElseIf op = "-" Then oper1 = oper2 - Val(display.Caption)
ElseIf op = "*" Then oper1 = oper2 * Val(display.Caption)

End If

If op = "/" Then
If Val(display.Caption) = 0 Then
MsgBox "Can't Divide by Zero!!"
Else
oper1 = oper2 / Val(display.Caption)
End If
End If

If op = "" Then oper1 = oper2 - Val(display.Caption)

oper2 = oper1
op = "-"
pop = op
display.Caption = oper2

End Sub

Private Sub minus_LostFocus(Index As Integer)
display.Caption = " "
End Sub

Private Sub mul_Click(Index As Integer)
If op = "+" Then
oper1 = Val(display.Caption) + oper2
ElseIf op = "-" Then oper1 = oper2 - Val(display.Caption)
ElseIf op = "*" Then oper1 = oper2 * Val(display.Caption)

End If

If op = "/" Then
If Val(display.Caption) = 0 Then
MsgBox "Can't Divide by Zero!!"
Else
oper1 = oper2 / Val(display.Caption)
End If
End If

If op = "" Then oper1 = oper2 * Val(display.Caption)

oper2 = oper1
op = "*"
pop = op

display.Caption = oper2
End Sub

Private Sub mul_LostFocus(Index As Integer)
display.Caption = ""
End Sub

Private Sub per_Click()

If oper1 <> 0 And Val(display.Caption) <> 0 Then
oper1 = Val(display.Caption) * oper1 / 100
display.Caption = oper1
Else
display.Caption = 0
End If
End Sub

Private Sub plus_Click(Index As Integer)

If op = "+" Then
oper1 = Val(display.Caption) + oper2
ElseIf op = "-" Then oper1 = oper2 - Val(display.Caption)
ElseIf op = "*" Then oper1 = oper2 * Val(display.Caption)
End If

If op = "/" Then
If Val(display.Caption) = 0 Then
MsgBox "Can't Divide by Zero!!"
Else
oper1 = oper2 / Val(display.Caption)
End If
End If

If op = "" Then oper1 = Val(display.Caption) + oper2

oper2 = oper1
op = "+"
pop = op
display.Caption = oper2
End Sub

Private Sub plus_LostFocus(Index As Integer)
display.Caption = " "
End Sub

Private Sub sqrt_Click()
display.Caption = Sqr(display.Caption)
End Sub

Private Sub upon_Click(Index As Integer)

display.Caption = 1 / Val(display.Caption)
End Sub

Private Sub upon_LostFocus(Index As Integer)

End Sub

 

dan jika kamu menginginkan aplikasi lengkap dengan source codenya silahkan download disini

 

Share this article :
 

+ comments + 2 comments

Anonymous
August 3, 2013 at 3:07 PM

linknya mati boss

August 3, 2013 at 7:33 PM

@Anonymous
unduh disini : http://www.4shared.com/zip/8MdIqy8l/kalkulator_1_.html

Post a Comment

Terima Kasih Sudah Meninggalkan Komentar...

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. ingin berbagi - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger