Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert string to number Jeff Klein Excel Worksheet Functions 4 November 1st 07 10:01 PM
Convert a string to number WLMPilot Excel Programming 3 March 28th 07 02:11 AM
Convert a number to a name string Numbers to name string Excel Worksheet Functions 2 June 23rd 06 04:52 PM
Convert a String to an number 11Oppidan Excel Programming 4 February 2nd 05 03:27 AM
convert string to number Christina Excel Worksheet Functions 3 November 16th 04 02:36 PM


All times are GMT +1. The time now is 07:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"