Convert Input String Formula to Number

  • Thread starter Thread starter Ken Hudson
  • Start date Start date
K

Ken Hudson

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
 
Sub DoMath()
MsgBox (Evaluate("=" & Application.InputBox(prompt:="enter string", Type:=2)))
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top