CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2000
    Location
    The Netherlands
    Posts
    26

    Calculating string sums

    I would like to know if there is any function in VB by which you can 'parse' a string containing a sum, like "1+1", and get a number containing the result. JavaScript has the eval() function which you can use for this purpose, but I have not been able to find any such function in VB. Any help would be greatly appreciated!


  2. #2
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Calculating string sums

    I am not sure if there is any function in VB to do so, but I can create a simply one by using Split() function. As following:

    ===
    Private Function GetSum(strTheSumString As String) As Long
    Dim str() As String
    Dim intRV As Integer

    str = Split(strTheSumString, "+")
    intRV = CInt(str(0)) + CInt(str(1))
    GetSum = intRV

    End Function

    ===

    Good luck!

    Regards,

    Michi
    MCSE, MCDBA

  3. #3
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: Calculating string sums

    Try this link it seems to do ehat you need!
    http://www.freevbcode.com/ShowCode.Asp?ID=1263

    Kris
    Software Engineer
    Phoenix,AZ
    Kris
    Software Engineer
    Phoenix, AZ USA

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

Featured