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!

Calculate Strings in Textboxes

Status
Not open for further replies.

theservant

Programmer
Aug 27, 2003
5
ZA
i have a problem calculating textboxes.

Let say that I have 3 textboxes: txtval1, txtval2 and txtval3

then I have a textbox that contains a formula called txtFormula and one called txtresult

is there a way that I can calculate whatever formule is placed in txtformula and have the result show in txtresult? I have tried scriptcontrol1.eval, but as soon as I link it to a textbox it gives me the text and not the result

Please help
 
Try this - It works where formula text is like X*Y+Z. With microsoft script control referenced

Dim myStr as string
Dim objScript As Object

Set objScript = CreateObject("MSScriptControl.ScriptControl")

objScript.Language = "VBScript"
mystr = txtFormula

mystr = Replace(mystr, "x", txtX, 1)
mystr = Replace(mystr, "y", txtY, 1)
mystr = Replace(mystr, "z", txtZ, 1)



txtResult = objScript.Eval(mystr)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top