用VB求数列1,2,3,5,16,231.......的前20项

来源:百度知道 编辑:UC知道 时间:2024/06/15 14:45:01

Dim n As Integer
Dim m As Integer
Dim i As Integer
Dim j As Integer
Dim a(30) As Integer '确定数组的范围()里的数即为最大可储存数+1
Private Sub Command1_Click()
m = 3 '定一变量,指定输入的排序数 如这为20
If (n < m) Then
If (Text1.Text = "") Then '判定输入数据是否为空
MsgBox "请输入数据!"
Text1.SetFocus '在text1文本上定位光标
Exit Sub
Else
n = n + 1 'n用于确定输入了的数据的个数
a(n) = Text1.Text '获取文本的数据
Text1.Text = ""
If n < m Then '使最后输入数据后不再定位光标
Text1.SetFocus
End If
End If
Else
For i = 1 To m Step 1 '循环嵌套排列输入的20个数的次序
For j = 1 To m - 1 Step 1
If a(j) > a(j + 1) Then
x = a(j)
a(j) = a(j + 1)
a(j + 1) = x
End If
Next j
Next i
n = n + 1 '用于跳转的下个K循环的前提条件
End If

If n = m Then '当输入20个数了,就改变按钮的显示文字
Command1.Caption = "计算"
End If

If n > m Then