I bought the book Visual Basic.net Core Reference by Francesco Balena and was hoping to learn Visual basic, but I’m already having problem on my first console code sample from the book. Do you think the book is too old and the samples are no longer compatible with today’s VB.net anymore? The compiler is prompting that I’m missing Sub Main(), but the sample in Francesco’s book doesn’t have Sub Main()
Module MathFunctions
'A public constant
Public Const DoublePI as Double = 6.2831853
'A private array
Private factValues(169) As Double
'Return the factorial of a number in the range 0-169
Public Function Factorial(ByVal n As Integer) As Double
'evvaluate all possible values in advance during the first call.
If factValues(0) = 0 Then
Dim i As Integer
factValues(0) = 1
For i = 1 To 169
factValues(i) = factValues(i - 1) * CDbl(i)
Next
End If
'check the argument
If n >= 0 And n <= 169 Then
'return the value in the array if argument is in range
Factorial = factValues(n)
Else
'raise an error otherwise
Err.Raise(6, , "Overflow")
End If
End Function
'The following code block (except End Module) is what I added to the code sample, but I'm still not getting any output from the console
Sub Main()
Factorial(32)
End Sub
End Module
The program is executing absolutely fine.
What you are probably expecting is to see the returned value from your function – however, you have not output it anywhere.
If you change your
Mainto the following, you will see a result: