Posted by : Unknown Friday, November 29, 2013

Untuk postingan kali ini ane akan sharing kepada ente para pembaca bloger ane semuanya yaitu source code cara membuat kalkulator sederhana menggunakan Visual Basic 6.


Source Code :
Option Explicit

Private hasil As Double
Private Const opNol = 0
Private Const opTambah = 1
Private Const opKurang = 2
Private Const opKali = 3
Private Const opBagi = 4
Private operator As Integer
Private NilaiBAru As Boolean


Private Sub hapus()
Dim txt As String
Dim min_len As Integer
txt = txtDisplay.Text
If Left$(txt, 1) = "_" Then
min_len = 2
Else
min_len = 1
End If
If Len(txt) > min_len Then
txtDisplay.Text = Left$(txt, Len(txt) - 1)
Else
txtDisplay.Text = "0"
End If
End Sub


Private Sub Command1_Click()
End
End Sub

Private Sub Command10Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command11PlusMinus_Click()
If NilaiBAru Then
Text1Display.Text = "-"
ElseIf Left$(Text1Display.Text, 1) = "-" Then
Text1Display.Text = Right$(Text1Display.Text, 2)
Else
Text1Display.Text = "-" & Text1Display.Text
End If
End Sub

Private Sub Command12Koma_Click()
If InStr(Text1Display.Text, ".") Then
Beep
Else
If NilaiBAru Then
Text1Display.Text = "."
NilaiBAru = False
Else
Text1Display.Text = Text1Display.Text & "."
End If
End If

End Sub

Private Sub Command13Operator_Click(Index As Integer)
Command19SamaDengan_Click
operator = Index
NilaiBAru = True
End Sub

Private Sub Command14Operator_Click(Index As Integer)
Command19SamaDengan_Click
operator = Index
NilaiBAru = True
End Sub

Private Sub Command15Operator_Click(Index As Integer)
Command19SamaDengan_Click
operator = Index
NilaiBAru = True
End Sub

Private Sub Command16Operator_Click(Index As Integer)
Command19SamaDengan_Click
operator = Index
NilaiBAru = True
End Sub

Private Sub Command17ClearEntry_Click()
Command17 ClearEntry = Clik
hasil = 0
operator = opNol
End Sub



Private Sub Command18Clear_Click()
Text1Display.Text = ""
End Sub

Private Sub Command19SamaDengan_Click()
Dim hasilbaru As Double
If Text1Display.Text = "" Then
hasilbaru = 0
Else
hasilbaru = CDbl(Text1Display.Text)
End If
Select Case operator
Case opNol
hasil = hasilbaru
Case opTambah
hasil = hasil + hasilbaru
Case opKurang
hasil = hasil - hasilbaru
Case opKali
hasil = hasil * hasilbaru
Case opBagi
'Tidak bisa dibagi nol
If hasilbaru = 0 Then
MsgBox "Tidak bisa dibagi 0", vbOKOnly + vbCritical, "Kalkulator Error"
Call Command18Clear_Click
Else
hasil = hasil / hasilbaru
End If
End Select
operator = opNol
NilaiBAru = True
Text1Display.Text = Format$(hasil)
End Sub

Private Sub Command1Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command2Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command3Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command4Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command5Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command6Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command7Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command8Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Command9Angka_Click(Index As Integer)
If NilaiBAru Then
Text1Display.Text = Format$(Index)
NilaiBAru = False
Else
Text1Display.Text = _
Text1Display.Text & Format$(Index)
End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
txtdisplay_keyup KeyCode, Shift
End Sub

Private Sub Text1Display_Change()
Text1Display.SelStart = Len(Text1Display.Text)
End Sub

Private Sub Text1Display_GotFocus()
Text1Display_Change
End Sub

Private Sub Text1Display_KeyPress(KeyAscii As Integer)
Dim ch As String
ch = Chr$(KeyAscii)
Select Case ch
Case "0"
commandAngka_Click 0
Case "1"
commandAngka_Click 1
Case "2"
commandAngka_Click 2
Case "3"
commandAngka_Click 3
Case "4"
commandAngka_Click 4
Case "5"
commandAngka_Click 5
Case "6"
commandAngka_Click 6
Case "7"
commandAngka_Click 7
Case "8"
commandAngka_Click 8
Case "9"
commandAngka_Click 9
Case "*", "x", "X"
cmdOperator_Click opKali
Case "+"
cmdOperator_Click opTambah
Case vbCrLf, vbCr, "="
cmdSamaDengan_Click
Case "-"
cmdOperator_Click opKurang
Case "."
cmdKoma_Click
Case "/"
cmdOperator_Click opBagi
Case "C", "c"
cmdClearEntry_Click
End Select
KeyAscii = 0
End Sub

Private Sub Text1Display_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyNumpad0
cmdAngka_Click 0
Case vbKeyNumpad1
cmdAngka_Click 1
Case vbKeyNumpad2
cmdAngka_Click 2
Case vbKeyNumpad3
cmdAngka_Click 3
Case vbKeyNumpad4
cmdAngka_Click 4
Case vbKeyNumpad5
cmdAngka_Click 5
Case vbKeyNumpad6
cmdAngka_Click 6
Case vbKeyNumpad7
cmdAngka_Click 7
Case vbKeyNumpad8
cmdAngka_Click 8
Case vbKeyNumpad9
cmdAngka_Click 9
Case vbKeyMultiply
cmdOperator_Click opKali
Case vbKeyAdd
cmdOperator_Click opTambah
Case vbKeySeparator
cmdSamaDengan_Click
Case vbKeySubtract
cmdOperator_Click opKurang
Case vbKeyDivide
cmdOperator_Click opBagi
Case vbKeyDecimal
cmdKoma_Click
Case vbKeyBack, vbKeyDelete
hapus
End Select
KeyCode = 0
End Sub

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Greeting

WELLCOME TO MY PAGE

Gunadama University

Student Site

StaffSite

Library Gunadarma

Popular Post

My Song

Powered by Blogger.

- Copyright © Erick Bashir " SAYDRO " -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -