Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim f As String
f = InputBox("請輸入求費氏第幾項係數?(3~30)")
MsgBox("費氏第 " & f & " 項係數為 : " & fib(Val(f)))
End'真按:原《Visual Basic 2010基礎必修課》書內無此式,程式無法自行結束
End Sub
Function fib(ByVal n As Integer) As Integer
If n = 1 Or n = 2 Then'真按:以此作為遞迴的終結
Return 1
Else
Return fib(n - 1) + fib(n - 2)
End If
End Function
End Class