Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a textbox to calculate like an excel cell

Status
Not open for further replies.

mwheads

Programmer
Apr 24, 2004
38
ZA
Hi Everyone

I would like to be able to use an unbound textbox to do a calcuation exactly the same way as an excel cell, before it is posted it to a bound textbox on a form. Is there a way?
I.e. I would like to enter "=50+100-20+600" and it to calculate that string as excel would.
PS. if I don't have to use an "=" it would be even better.

Thanks
Paul
South Africa
 
the method that springs to mind is to use a text box, a list box and a 2 cmd buttons

in the text box the user inputs the first digit eg 5

then clicks a cmd button for add, the number five is then added as a line in the list box, also the number five is stored in a variable (called varSum)


then the user types the next part of the sum, eg + 6, this is added to another line on the text box and then in vba we put

'add the user input to the formula
varSum = varSum + txtSum.text


'set focus back to text box
textSum.setfocus

'clear text box ready for input
txtSum.text = ""

(NB a + and a + always make a + and a + and a - always make a -, so the + isnt going to affect your equation)

Now make use of a case select function, whereby if the user puts = in the text box then txtSum.text = varSum and the list box adds a line of ______ and then a line with the answer or something.

the second cmd button is used as a clear key. ie it clears the text box and list box and the variable.



Thats not a very detailed explanation and assumes you have some knowledge of VB, if you need more help then please ask


 
Take a look at the Eval function, in the AfterUpdate event procedure of TextBox1:
myCalc = Eval(Me!TextBox1.Text)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks PHV and SillySod, both work well, and both have been implemented. Thanks for the extra knowledge and expertise,
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top