Results 1 to 2 of 2

Thread: Noob Question - getting the sum of a string of numbers?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    1

    Unhappy Noob Question - getting the sum of a string of numbers?

    Hello everybody,
    I am a beginner in the world of VB - although i do have a medium knowledge of Python, HTML/CSS.
    I am working on my first basic program.
    a simple calculator.
    Buttons representing numbers 0-9
    Buttons with + - x / =
    and a clear button.

    So what ive done is created a string, and when the user hits the button, it adds that value to the string (hit buton 4, it adds a 4, hit the minus, it adds a -)
    i need a "function" that grabs that string, uses logical math on it, to determine the answer. I know in Python you can use:
    Eval(STRING NAME)
    is there an equivelant for VB?

    any help, will be greatly appreciated!!
    Gobble45

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Noob Question - getting the sum of a string of numbers?

    there's no exact equivalent, but you can use this. notice the parentheses to establish operator precedence:

    vb Code:
    1. Dim dt As New DataTable
    2. Dim answer As Integer = CInt(dt.Compute("((1 + 2 + 3) * 5) / 3", Nothing))

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