Results 1 to 14 of 14

Thread: Mathematical expressions solving

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    9

    Question

    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]
    Yotam Harchol
    yotam83@hotmail.com
    VB6 Enterprise / Win 2000

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  3. #3
    Guest
    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...

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Roblll's code is better then mine, so use that code.
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  5. #5
    Guest
    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.)

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    9

    Wink thank u

    10x 4 helping me! It was very helpful.
    Yotam Harchol
    yotam83@hotmail.com
    VB6 Enterprise / Win 2000

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Unhappy

    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Guest

    Thumbs down same error

    Hi.

    It happens the same to me.

    numibesi

  9. #9
    Guest

    Question

    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...

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    9

    Unhappy

    I think that the only way is to write a function that searched the string char by char and solve it... :-(
    Yotam Harchol
    yotam83@hotmail.com
    VB6 Enterprise / Win 2000

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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 refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Guest
    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.

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    And i was thinking this was exactly what i need, it's tons faster than vbs, but it doesn't work after compilation
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    9

    Angry Help!

    Does any1 have idea??
    Yotam Harchol
    yotam83@hotmail.com
    VB6 Enterprise / Win 2000

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width