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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math expressions in Text Boxes

Status
Not open for further replies.

domt

Programmer
Mar 13, 2001
115
US
Does anyone know a way to solve a math expression that a user types in a text box? For example if a user types 3*12/8, or 5*Sin(40) in a text box, Is there a method or routine that produces an answer?
Any help will be appreciated.
 
A quick search on 'eval' brings several results, including thread222-792530

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Essex Steam UK for steam enthusiasts
 
Add to the components the Script control. Not only it can evaluate expressing such as these mentioned by you, but also these: 3+x/5 where x is a variable and you will assign it a value from a text box


-
 
Thanks for your replies,
But how does one load ScriptControl? I don't have it in my AddIns. I have VB6 with SP5.
 
The best way is to execute the expression thru a SQl statement. Use dummy table.

For Example
text1.text="3*12/8, or 5*Sin(40)"
xStr=text1.text
set rs=mycon.execute ("select top 1" & xstr " from table1")
xresult=rs.fields(0)


Hope this would solve your problem.
 
Script control - as seen in my previously referred thread - is available (if you don't have it) from:

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Essex Steam UK for steam enthusiasts
 
Thanks much.
I downloaded the file and it now resides in a folder in Program Files.
Now how do I get it in my addins list?
 
Project|References menu

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Essex Steam UK for steam enthusiasts
 
Thank you
I just came across that solution myself.
I set up a test program to learn to use Script control.
I defined some letters, A, B, etc. to represent numbers.
When I enter these letters into a text box by code, Script control doesn't recognize them. Is there a remedy for this?
 
Eval accepts a string as an argument.

Debug.Print Eval("4 * 5")

If you want t use variables build the string using normal concatenation rules:
a = 5
b = 4
Debug.Print Eval(a & "*" & b)



________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Essex Steam UK for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top