• PW (3/9/2005)


    The sample VB.net code for comparison contains both syntax and logic errors.

    In VB.Net, an IF is ended by "End If", not End.

    Also, "

    Refactored code:

    Private Function Factorial(ByVal number As Integer) As Integer

    If number = 0 Then

    Return 1

    Else

    Return (number * Factorial(number - 1))

    End If

    End Function

    Shouldn't the exit condition for this be "if number = 1"? Since you're multiplying by "number -1", and "1 -1" = 0, it seems like you would end up multiplying by 0, and thus getting 0 as your result every time. (It's been a while since I played with VB, so I'm not certain on this.)

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon