Results 1 to 6 of 6

Thread: use Val () function with strings that contain +,-,*,/

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    I am trying to get a numberic value of a string variable that is , for example "3 + 6 + 7 - 9 * 2"
    What I want this to do is evaluate this as a mathematical value and assign it to a number value
    The following does not work
    dblValue = Val(strEquation)
    This value gets returned as the first number in the sequence of the string variable (in this case it will equal 3)
    I also tried removing the spaces as well as putting in parentheses. It doesn't work.

    Is there another way or something I'm missing? It would really help me out. Thanks.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You will have to make a script that reads those strings and calculates them manually.

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    There's something called uMath which can do it, I think it's about $100 but it's damn usefull if you need to do a lot of this stuff, otherwise, program your own. VB can't do it, I don't know where uMath is but search under Maths parser.

  4. #4
    New Member
    Join Date
    Mar 2000
    Posts
    3
    the val() function converts every digit until it encounters the first non-digit number. Valid characters aree 0-9 the sign (+ or -) and the decimal point(.)
    to convert a string to a mathmatical sequence try the eval() method. It evaluates a supplied string as though it were code. As a result, you could easily evaluate mathematical expressions passed as a string, like so:

    iResult = Eval("(2 * 3) + 5)")

    which fills iResult with the value 11.

  5. #5

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    Yes I would like to see the code if you can share it, thanks.


    I have done some code that does this thing, but I think it's a bit slow for use. Interested?

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The module is at:
    http://www.geocities.com/kedasu/varol.bas
    It's somewhat old, I haven't used it for years. Don't worry about those swedish comments. If anyone finds it useful or finds any bugs, reply here or contact me

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