Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15496

VS 2019 Return statement not returning correct value

$
0
0
Here is the code (within a class):
Code:

Function GCD(Num1 As Integer, Num2 As Integer) As Integer
        'Debug.Print("1st " & Num1 & " 2nd " & Num2)
        ' use Euclid's algorithm
        ' Greatest Common Divisor (GCD) of two integers A and B is the largest integer that divides both A and B.

        If Num1 Mod Num2 = 0 Then
            Debug.Print(Num2)
            Return Num2
        Else
            GCD(Num2, Num1 Mod Num2)
        End If
        'Return
    End Function

Her is the output:

6
GCD of 270 and 192 is 0
The program '[16176] TestApp.exe' has exited with code 0 (0x0).

Calling module:
Debug.Print("GCD of " & Num1 & " and " & Num2 & " is " & myFact.GCD(Num1, Num2))

Issue:
Why does the return not give a '6' as it should?

Viewing all articles
Browse latest Browse all 15496

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>