[AccessD] add numbers

Stuart McLachlan stuart at lexacorp.com.pg
Tue Apr 12 16:58:23 CDT 2005


On 12 Apr 2005 at 22:51, Pedro Janssen wrote:

> Hello Stuart,
> 
> thanks for your help. The function works perfect.But i forgot to tell that
> in the field [Para], also "normal" values are present like from 1 to 9. When
> using the function i get an error.on the: While InStr..... I tried to adjust
> the code, with no result.
> 

Me bad, I didn't check for the end of the string in the While Loop.
Try this one instead (watch for line wrap)

Function Addnumbers(InputString As String) As Double
   Dim lngStore As Double
   Dim lngLoopcount As Double
   lngLoopcount = 0
   Do
     lngLoopcount = lngLoopcount + 1
         lngStore = lngStore + Val(Mid$(InputString, lngLoopcount))
         'move past current number
         While InStr("0123456789+-", Mid$(InputString, lngLoopcount, 1)) > 0  And lngLoopcount <= Len(InputString)
             lngLoopcount = lngLoopcount + 1
         Wend
   Loop Until lngLoopcount >= Len(InputString)
   Addnumbers = lngStore
End Function-- 
Stuart





More information about the AccessD mailing list