I guess you're only adding integers since your "first" and "second" variables are longs.
I think that this is what you want to do. If it's not quite what you need, post back.
Private Sub cmdPlus_Click()
if (something) then ' This has to flag the condition that he has just entered a number and hit "+". There has to be something left empty to show that he wants to use the last entered value as an operand. This is the fundamental problem in the code.
Calculated = False
else
Calculated = True
end if
If Calculated = True Then ' As originally written, this Calculated will always be True.
' I assume that this part works.
first = Val(TextDisplay.Text)
TextDisplay.Text = ""
second = Val(TextDisplay.Text)
first = first + second
second = 0
TextDisplay.Text = first
second = 0
Else
first = Val(TextDisplay.Text) ' This is the value on the screen.
second = val(TextNum1.Text) ' Pick up the value that he just entered
TextNum1.Text = first
first = first + second
TextDisplay.Text = first
sign = cmdPlus.Caption ' I'm not sure what you're using this for.
' I think you wanted this subroutine to be called automatically and you'd use the "Calculated" variable to steer the program flow. There are two problems with your approach. 1) there's nothing to trigger the event (you could deliberately call this subroutine again), and 2) Calculated is a local variable, not a global variable. A new variable, Calculated is created and set each time this subroutine is called. I suggest you just calculate the value you want in the "else" section of the program. If the user hasn't entered a variable, jump to the else section.
End If
End Sub
In most calculators, I believe they remember the second number you typed in. The Windows calculator remembers the last calculated value. It doesn't display either one. You could just put it in a variable that persists from one operation to the next, and never show it on the screen. Alternatively, you could put it in a textbox that is disabled (textboxname.enabled = false). It would be grayed out, but the user could still see what's saved. In the above, you would select "first" from the box where he entered a value and "second" from this grayed out box (or the hidden variable). If "C"lear is clicked, be sure to zero the saved textbox or the variable.
|