neo_lover2000
Jun 1, 2009, 03:10 AM
I already finish a very simple calculator,actually it has only four buttons.
at first its working fine but when add another feature its not working anymore.
I will describe first the appearance of my calculator, its has a button for number 1, plus button, equals button, clear button, it has four text box, the textDisplay for the result. Num1.text to display first number, num2.text to display second number and flag.text to display temporary value(sum of first and second number).
what I want to do now is to display the sum of first and second number on the textDisplay when I press + button then getting ready to enter new number and so on.
for example: 1+1+1+1...
to all master there I am getting confuse on setting a flag can you please explain how to set and how it works?
I attaché my program.
if the process is 1+1 = result, I make it work but when I added new process I'm lost.
thanks
Dim first As Long
Dim second As Long
Dim sign As String
Dim Calculated As Boolean
Private Sub Command1_Click()
TextDisplay.Text = TextDisplay.Text + Command1.Caption
End Sub
Private Sub cmdPlus_Click()
Calculated = True
If Calculated = True Then
first = Val(TextDisplay.Text)
TextDisplay.Text = ""
second = Val(TextDisplay.Text)
first = first + second
TextDisplay.Text = first
second = 0
Else
first = Val(TextDisplay.Text)
TextNum1.Text = first
TextDisplay.Text = ""
sign = cmdPlus.Caption
End If
End Sub
Private Sub cmdC_Click()
TextDisplay.Text = ""
TextNum1.Text = ""
TextNum2.Text = ""
TextFlag.Text = ""
End Sub
Private Sub cmdEq_Click()
second = Val(TextDisplay.Text)
TextNum2.Text = second
If sign = "+" Then
TextDisplay = first + second
End If
End Sub
at first its working fine but when add another feature its not working anymore.
I will describe first the appearance of my calculator, its has a button for number 1, plus button, equals button, clear button, it has four text box, the textDisplay for the result. Num1.text to display first number, num2.text to display second number and flag.text to display temporary value(sum of first and second number).
what I want to do now is to display the sum of first and second number on the textDisplay when I press + button then getting ready to enter new number and so on.
for example: 1+1+1+1...
to all master there I am getting confuse on setting a flag can you please explain how to set and how it works?
I attaché my program.
if the process is 1+1 = result, I make it work but when I added new process I'm lost.
thanks
Dim first As Long
Dim second As Long
Dim sign As String
Dim Calculated As Boolean
Private Sub Command1_Click()
TextDisplay.Text = TextDisplay.Text + Command1.Caption
End Sub
Private Sub cmdPlus_Click()
Calculated = True
If Calculated = True Then
first = Val(TextDisplay.Text)
TextDisplay.Text = ""
second = Val(TextDisplay.Text)
first = first + second
TextDisplay.Text = first
second = 0
Else
first = Val(TextDisplay.Text)
TextNum1.Text = first
TextDisplay.Text = ""
sign = cmdPlus.Caption
End If
End Sub
Private Sub cmdC_Click()
TextDisplay.Text = ""
TextNum1.Text = ""
TextNum2.Text = ""
TextFlag.Text = ""
End Sub
Private Sub cmdEq_Click()
second = Val(TextDisplay.Text)
TextNum2.Text = second
If sign = "+" Then
TextDisplay = first + second
End If
End Sub