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

Math Equations 1

Status
Not open for further replies.

JaeBrett

Programmer
May 5, 2003
196
0
0
CN
I have a few text boxes that are all filled with numbers. How can I do an equation to change the String's to numbers to multiple them together?

Thanks
 
Assign an integer variable to the Text property of each of the textboxes, then display the result of the 2 integers added together in the Total textbox.
 
myTotal = val(Text1.text) * Val(Text2.text)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
JESTAR
Would you care to explain that comment?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
You just owned my rudimentary answer with a simpler 1 line answer that I completely forgot about. I can now rewrite my program using that. :(
 
[smile]

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
isn't there a scripting command for this...

Ahhh, found it...

Here's a VB Eval function:

Public Function vbEval(strSource As String) As Variant
Dim wsh As Object

Set wsh = CreateObject("MSScriptControl.ScriptControl")
wsh.Language = "vbscript"

vbEval = wsh.Eval(strSource)
Set wsh = Nothing
End Function


Originally posted by StrongM

in thread: thread222-453764

You Could Use it in your case like this:

Text3 = vbEval("(" & Text1 & ")*(" & Text2 &")")

then you could even use fractions....

text1 = 1/2 and text2 = 10
it would evaluate to this...
(1/2)*(10) = (.5)*(10) = (5)
So text3 would = 5

This Would Work Good for a calculator program...

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Josh, it'd be nice if you at least credited the thread - thread222-573955 - (if not the author) when quoting code.
 
So you did. How on earth did I miss that? My apologies.
 
Come On Now... I might like to argue my opinion every now and then just for fun, but I still give credit where it is due;-)

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top