Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim no As Integer
    no = Val(TextBox1.Text)
    fact(no)
    Dim ans As Integer = 0
End Sub
Function fact(ByVal no As Integer) As Integer



    If no > 0 Then


        ans = ans + (no * fact(no - 1))
        TextBox2.Text = ans

    End If
End Function

End Class

You need to account for all cases. Your function does nothing for Fact(0). You should also just return a value rather than assign it to the textbox in the function.

Private Function Fact(no As Integer) As Integer

    If no > 1 Then
        Return no * Fact(no - 1)
    Else
        Return 1
    End If

End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.