Click to See Complete Forum and Search --> : Calculating string sums


vampyre
July 12th, 2001, 03:56 PM
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!

michi
July 12th, 2001, 04:08 PM
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

softweng
July 12th, 2001, 05:51 PM
Try this link it seems to do ehat you need!
http://www.freevbcode.com/ShowCode.Asp?ID=1263

Kris
Software Engineer
Phoenix,AZ