Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Convert Input String Formula to Number
I have an input box that prompts the user for a math formula, e.g. 5+3-2.5/6
How can I get VB to do the math on that string and return the answer? Option Explicit Dim InpStr As String Dim Ans as Double Sub DoMath() InpStr = InputBox("Enter formula.") Ans = convert InpStr to formula and solve MsgBox "Answer is: " & Ans End Sub -- Ken Hudson |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Convert Input String Formula to Number
Sub DoMath()
MsgBox (Evaluate("=" & Application.InputBox(prompt:="enter string", Type:=2))) End Sub -- Gary''s Student - gsnu200772 "Ken Hudson" wrote: I have an input box that prompts the user for a math formula, e.g. 5+3-2.5/6 How can I get VB to do the math on that string and return the answer? Option Explicit Dim InpStr As String Dim Ans as Double Sub DoMath() InpStr = InputBox("Enter formula.") Ans = convert InpStr to formula and solve MsgBox "Answer is: " & Ans End Sub -- Ken Hudson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Convert Input String Formula to Number
Thank you.
-- Ken Hudson "Gary''s Student" wrote: Sub DoMath() MsgBox (Evaluate("=" & Application.InputBox(prompt:="enter string", Type:=2))) End Sub -- Gary''s Student - gsnu200772 "Ken Hudson" wrote: I have an input box that prompts the user for a math formula, e.g. 5+3-2.5/6 How can I get VB to do the math on that string and return the answer? Option Explicit Dim InpStr As String Dim Ans as Double Sub DoMath() InpStr = InputBox("Enter formula.") Ans = convert InpStr to formula and solve MsgBox "Answer is: " & Ans End Sub -- Ken Hudson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
convert string to number | Excel Worksheet Functions | |||
Convert a string to number | Excel Programming | |||
Convert a number to a name string | Excel Worksheet Functions | |||
Convert a String to an number | Excel Programming | |||
convert string to number | Excel Worksheet Functions |