VB问题~~~~~~~

来源:百度知道 编辑:UC知道 时间:2024/06/11 00:15:10
以下数列:1、1、2、3、5、8、13、21、…,规律是从第3个数开始,每个数是它前面两个数之和。选中一个单选按钮后,单击“计算”按钮,则计算出上述数列的第n项值,并显示在文本框中,n是选中的单选按钮后面的数值。

还有putdata怎么用的

问题1:

放置Text1和Text2还有Command1
添加代码:

Private Function Fib(n As Integer) As Long
Dim res() As Integer
ReDim res(1 To n + 10)
res(1) = 1: res(2) = 1
For i = 3 To n
res(i) = res(i - 1) + res(i - 2)
Next i
Fib = res(n)
End Function

Private Sub Command1_Click()
Dim n As Integer
n = Text1
Text2 = Fib(n)
End Sub

Private Sub Form_Load()
Width = 3300
Height = 2000
Text1.Left = 100
Text1.Top = 100
Text1.Width = 3000
Text1.Height = 300
Text1.Text = ""
Text2.Left = 100
Text2.Top = 500
Text2.Width = 3000
Text2.Height = 300
Text2.Locked = True
Text2.Text = ""
Command1.Left = 1000
Command1.Top = 1000
Command1.Width = 1300
Command1.Height = 500
Command1.Caption = "计算