'********************************************************************

'*

'* Function Sqroot

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2004-12-03

'* Modified: 2004-12-03

'*

'* Purpose: Calculate the Square Root of a number using the Newton-

'*            Rasphson method.

'*

'* Input: numAny = A whole number of any size from 1 to infinite.

'*

'* Output:  The square root of the number.

'*

'********************************************************************

Function Sqroot(ByVal numAny)

  'Version 1.0 2004-12-03

  Dim intProgress, intCount, intStart, intFactor

  Dim numerator, denominator

 

  'Rather than calculate a better start value, i choose to loop

  'more times. This requires a little more processing time, but

  'this is not noticable.

  Const maxLoops = 30

  intCount = 0

  'Default Start Value, you could devise a method to estimate a start

  'value to reduce the number of loops.

  intStart = 2

  intFactor = intStart

  Do

    intCount = intCount + 1

    numerator = (intFactor^2) - numAny

    denominator = intStart * intFactor

    intProgress = intFactor - (numerator/denominator)

    intFactor = intProgress

  Loop Until (intProgress^2 = numAny) Or intCount = maxLoops

  Sqroot = intProgress

End Function 'Sqroot

Article ID: 421, Created On: 9/25/2011, Modified: 9/25/2011