-
Does some1 have a function or anything else that solves mathematical expressions?
The function should get a string (the expression) and return a double (the solution)
(4 Example: the string is "2.4-5.3*2-4(5+3)/sin(3.2)" so the function should return 688.66106 - i'm not sure but i think that this is the correct answer)
[Edited by yotam on 11-22-2000 at 08:51 AM]
-
-
a) The Answer is (according to my calculations) : 539,987915420116
b) Try this code:
Code:
Option Explicit
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Foo1 As Long, ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
' For VB5
'Declare Function EbExecuteLine Lib "vba5.dll" (ByVal pStringToExec As Long, ByVal Foo1 As Long, ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
' For Access 97/VBE.dll clients as Word 97 and Excel 97
'Declare Function EbExecuteLine Lib "vba332.dll" (ByVal pStringToExec As Long, ByVal Foo1 As Long, ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
Function FExecuteCode(stCode As String, Optional fCheckOnly As Boolean) As Boolean
FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
Private Sub Form_Load()
Dim TheQuestion As String
TheQuestion = "2.4-5.3*2-4*(5+3)/sin(3.2)"
FExecuteCode "Q = " & TheQuestion
FExecuteCode "MSGBox ""The answer to the question " & vbCrLf & vbCrLf & TheQuestion & vbCrLf & vbCrLf & "is : "" & vbCrLf & vbcrlf & Q"
End Sub
Now you're basically running an interpreter...
-
Roblll's code is better then mine, so use that code.
-
The anser is 688,661068746521 for the formula: (2.4-5.3*2-4*(5+3))/sin(3.2)
(Just to let you know I know what I'm talkin' 'bout.) ;)
-
thank u
10x 4 helping me! It was very helpful.
-
Does this work for anyone else, i mean after you compile, it says you need vba6.dll, and when you put it in the same directory it crashes.
-
same error
Hi.
It happens the same to me.
numibesi
-
Dunno... Never compiled it...yet...Lemme try...
The instruction at "0x0fa916cc" referenced memory at "0x000002b0". The memory could not be "read".
Uhm... Servicepack 5????? Maybe you'd have to DIM first???
Nope...Same error...
Lemme try sometin' else...
Code:
Private Sub Form_Load()
' This time without variables...
FExecuteCode "MSGBox ""The answer to the question is : "" & vbCrLf & vbcrlf & "" (2.4-5.3*2-4*(5+3)/sin(3.2))"
End Sub
Doesn't work either... Anyone? I'm out of ideas...
-
I think that the only way is to write a function that searched the string char by char and solve it... :-(
-
To solve an equation, first you need to move it into Reverse Polish Notation. To do this, first the brackets need to be split, for example:
x = 1 * 6 * (9 + 3 * sin(y))
goes to:
x = 1 * 6 * par_a
par_a = 9 + 3 * par_b
par_b = sin y
Then, you can parse it out (can't remember how, look for "Reverse Polish" on a search engine, or someone here MUST know!). Then substitute the values back in again.
-
I know it sounds lame now... But I once had a "parsing and processing" routine that did it.. Can't remember where I left it (maybe on work, couldn't dig it up here), but also I think to recall I found it here... As I remember it was a CLASS...
I'll try to find it monday at work... E-mailed to my job to not forget it... I'll keep you up to date...
Rob.
-
And i was thinking this was exactly what i need, it's tons faster than vbs, but it doesn't work after compilation :(
-
Help!