PC Review


Reply
Thread Tools Rate Thread

Convert Input String Formula to Number

 
 
Ken Hudson
Guest
Posts: n/a
 
      11th Mar 2008
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 With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      11th Mar 2008
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 With Quote
 
Ken Hudson
Guest
Posts: n/a
 
      11th Mar 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
validate that string input is a negative number =?Utf-8?B?ZGlhdG9tQG5ld3Nncm91cC5ub3NwYW0=?= Microsoft C# .NET 6 28th Mar 2007 07:37 PM
RE: validate that string input is a negative number =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?= Microsoft C# .NET 0 28th Mar 2007 12:13 AM
Convert a number from a string into number format =?Utf-8?B?U2FuZHk=?= Microsoft Access Queries 2 21st Feb 2007 08:23 PM
Addition string from input box in to a formula (eg;R1C1 Formula) =?Utf-8?B?RGV2?= Microsoft Excel Programming 2 31st Jan 2007 07:36 PM
Code to convert text input to a number FCC Microsoft Excel Programming 3 7th Aug 2006 09:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 PM.