main page >programming tips (VB5/6) >  Calculate the Greatest Common Divisor     diese Seite auf deutsch diese Seite auf deutsch
 
Use this function to calculate te Greatest Common Divisor of two Longs a and b:

Function GCD(ByVal a As Long, ByVal b As Long) As Long
Dim h As Long

    If a Then
        If b Then
            Do
                h = a Mod b
                a = b
                b = h
            Loop While b
        End If
        GCD = Abs(a)
    Else
        GCD = Abs(b)
    End If
    
End Function
            
main page >  programming tips (VB5/6) >  this page