0

我买了 Francesco Balena 的 Visual Basic.net Core Reference 一书,并希望学习 Visual Basic,但我在本书的第一个控制台代码示例上已经遇到了问题。你是不是觉得这本书太老了,样本不再兼容今天的 VB.net?编译器提示我缺少 Sub Main(),但 Francesco 书中的示例没有 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
4

1 回答 1

0

该程序执行得非常好。

您可能期望看到函数的返回值 - 但是,您没有在任何地方输出它。

如果您将您的更改Main为以下内容,您将看到结果:

Sub Main()
 Console.WriteLine(Factorial(32))
End Sub
于 2012-05-12T19:46:45.573 回答