Objek / Kontrol | Properties | Nilai |
Form | Nama Caption | Form1 Form Kalkulator |
Label | Nama Caption | Label1 Expresi |
TextBox | Caption | TxtExpresi |
Command1 | Nama Caption | CmdUlang ULANG |
Command2 | Nama Caption | cmdTombol 7 |
Command3 | Nama Caption | cmdTombol 8 |
Command4 | Nama Caption | cmdTombol 9 |
Command5 | Nama Caption | cmdTombol 4 |
Command6 | Nama Caption | cmdTombol 5 |
Command7 | Nama Caption | cmdTombol 6 |
Command8 | Nama Caption | cmdTombol 1 |
Command9 | Nama Caption | cmdTombol 2 |
Command10 | Nama Caption | cmdTombol 3 |
Command11 | Nama Caption | cmdTombol 0 |
Command12 | Nama Caption | CmdOperator + |
Command13 | Nama Caption | CmdOperator - |
Command14 | Nama Caption | CmdOperator x |
Command15 | Nama Caption | CmdOperator / |
Command16 | Nama Caption | CmdSamaDengan = |
Ketik kode program berikut :
Private Sub CmdAngka_Click(Index As Integer)
End Sub
Private Sub cmdOperator_Click(Index As Integer)
If TxtExpresi.Text = "" Then
JlhOperator = 0
Exit Sub
End If
If Cek Then Exit Sub
JlhOperator = JlhOperator + 1
If JlhOperator > 1 Then Exit Sub
TxtExpresi.Text = TxtExpresi.Text + CmdOperator(Index).Caption
Operator = CmdOperator(Index).Caption
Operand1 = Val(Nilai)
Nilai = ""
End Sub
Private Sub cmdSamaDengan_Click()
If TxtExpresi.Text = "" Then Exit Sub
If Cek Then Exit Sub
If JlhOperator = 0 Then
TxtExpresi.Text = TxtExpresi.Text & "=" & Nilai
Cek = True
Exit Sub
End If
Operand2 = Val(Nilai)
Select Case Operator
Case "+"
TxtExpresi.Text = TxtExpresi.Text & "=" & Operand1 + Operand2
Case "-"
TxtExpresi.Text = TxtExpresi.Text & "=" & Operand1 - Operand2
Case "x"
TxtExpresi.Text = TxtExpresi.Text & "=" & Operand1 * Operand2
Case Else
TxtExpresi.Text = TxtExpresi.Text & "=" & Operand1 / Operand2
End Select
Cek = True
JlhOperator = 0
End Sub
Private Sub cmdTombol_Click(Index As Integer)
If Cek Then
cmdUlangi_Click
Cek = False
End If
TxtExpresi.Text = TxtExpresi.Text + cmdTombol(Index).Caption
Nilai = Nilai + cmdTombol(Index).Caption
End Sub
Private Sub CmdUlang_Click()
Nilai = ""
TxtExpresi.Text = ""
JlhOperator = 0
End Sub
Private Sub Form_Load()
Cek = False
JlhOperator = 0
End Sub
Private Sub TxtExpresi_Change()
End Sub