求斐波拉契数列
Option Compare Database
Private Sub btnP_Click()
Dim i As Integer
Dim s As Integer
'*****Add1*****
Dim f(19) '定义数组,长度为19
s = 2
'*****Add1*****
f(1) = 1: f(2) = 1
For i = 3 To 19
'*****Add2*****
f(i) = f(i - 1) + f(i - 2)
s = s + f(i)
'*****Add2*****
Next i
'数据输出到文本框内
'*****Add3*****
Me.tData.Value = s 'me可能代表当前窗体,tData控件名称
'*****Add3*****
'以下是文件操作
If Dir(CurrentProject.Path & "\out.dat", vbDirection) <> vbNullString Then
Kill CurrentProject.Path & "\out.dat"
End If
Open CurrentProject.Path & "\out.dat" For Output As #1
Print #1, Me!tData
Close #1
End Sub