VB6.0:Calculator
Hi im new here.. anyone can help me with my program... please..
i have a project calculator using VB6 with the combination of operation like this
100 + 50 - 20 * 2 = 260 please help me.. thank you..
VB6.0:Calculator
Hi im new here.. anyone can help me with my program... please..
i have a project calculator using VB6 with the combination of operation like this
100 + 50 - 20 * 2 = 260 please help me.. thank you..
Here is the complete code on building a calculator app.:)
Just add the controls as required....
Option Explicit
Dim tempstore As Double
Dim operation As Byte
Private Sub cmd0_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "0"
End If
End Sub
Private Sub cmd1_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "1"
End If
End Sub
Private Sub cmd2_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "2"
End If
End Sub
Private Sub cmd3_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "3"
End If
End Sub
Private Sub cmd4_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "4"
End If
End Sub
Private Sub cmd5_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "5"
End If
End Sub
Private Sub cmd6_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "6"
End If
End Sub
Private Sub cmd7_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "7"
End If
End Sub
Private Sub cmd8_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "8"
End If
End Sub
Private Sub cmd9_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "9"
End If
End Sub
Private Sub cmdAddSubtract_Click()
If txtbox.Text = "" Then
MsgBox "You must enter a value", vbExclamation, "Temasek Calculator"
Else:
txtbox.Text = txtbox.Text * -1
Exit Sub
End If
End Sub
Private Sub cmdpoint_Click()
If Len(txtbox.Text) > 10 Then
Exit Sub
Else:
txtbox.Text = txtbox.Text + "."
End If
End Sub
Private Sub cmdSqRt_Click()
If txtbox.Text = "" Then
MsgBox "You must enter a value", vbExclamation, "Temasek Calculator"
Else
On Error GoTo err:
txtbox.Text = Sqr(txtbox.Text)
Exit Sub
err:
MsgBox "Cannot square root a negative value", vbExclamation, "Calculator"
txtbox.Text = ""
End If
End Sub
Private Sub Command14_Click()
operation = 1
tempstore = Val(txtbox.Text)
txtbox.Text = ""
End Sub
Private Sub Command15_Click()
operation = 2
tempstore = Val(txtbox.Text)
txtbox.Text = ""
End Sub
Private Sub Command16_Click()
operation = 3
tempstore = Val(txtbox.Text)
txtbox.Text = ""
End Sub
Private Sub Command17_Click()
operation = 4
tempstore = Val(txtbox.Text)
txtbox.Text = ""
End Sub
Private Sub Command18_Click()
If operation = 1 Then
txtbox.Text = CStr(tempstore + Val(txtbox.Text))
ElseIf operation = 2 Then
txtbox.Text = CStr(tempstore - Val(txtbox.Text))
ElseIf operation = 3 Then
txtbox.Text = CStr(tempstore * Val(txtbox.Text))
ElseIf operation = 4 Then
If txtbox.Text = 0 Then
MsgBox "Cannot divide by zero", vbCritical
txtbox.Text = ""
Exit Sub
Else
txtbox.Text = CStr(tempstore / Val(txtbox.Text))
End If
End If
End Sub
Private Sub Command19_Click()
txtbox.Text = ""
End Sub
Private Sub mnuAbout_Click()
frmAbout.Show vbModal
End Sub
Private Sub mnuExit_Click()
Unload Me
End Sub
@Mr. AdreRet > Thank you for giving this code sir.. but it doesnt give the exact answer.. :(
It actually does.:)
If you build the calculator, you will notice that you will be able to -
Enter 100, click on the plus button, enter 50, click on the minus button, enter 20 and so on. This will do your calculation showing the answer of 260 when the equal button is clicked on.
Is this not what you wanted?;)
thank you sir..
It was a pleasure.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.