作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/28 05:07:21
用VB求数列1,2,3,5,16,231.的前20项
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
Text2.Text = ""
For k = 0 To m - 1 Step 1 'K循环 输出循环
Text2.Text = Text2.Text & a(k + 1) & " "
Next k
Command1.Enabled = False '冻结按钮
Text1.Enabled = False '冻结输入文本框
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Label1.Caption = ""
Command1.Caption = "输入"
Command2.Caption = "退出"
Text2.Width = 5895
Text2.Height = 375
Text2.Top = 2520
Text2.Locked = True
Label1.Caption = "前20项的次序为:"
Label1.Width = 2775
Label1.Top = 2040
Text1.Top = 360
Text1.Width = 1215
End Sub
2个默认的按钮command,2个默认文本text,1个Label
各方面都想得基表全面了吧.