VB 二级考试题目

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:26:06
Option Base 1
Private Sub Sort(a() As Integer)
Dim Start As Integer, Finish As Integer
Dim i As Integer, j As Integer, t As Integer
Start = LBound(a)
Finish = UBound(a)
For i = Finish To 2 Step -1
For j = 1 To Finish - 1
If a(j) > a(j + 1) Then
t = a(j + 1)
a(j + 1) = a(j)
a(j) = t
End If
Next j
Next i
End Sub
End Sub

Private Sub Cmd1_Click()
Dim arr1
Dim arr2(4) As Integer
arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text))
temp = (Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) + Val(Text4.Text)) / 4
For i = 1 To 4
'?
Next i
Sort arr2()
Text1.Text = arr2(1)
Text2.Text = arr2(2)
Text3.Text = arr2(3)
Text4.Text = arr2(4)
'Form1.Ca

题目中说将平均值显示在窗体标题上,temp就是平均值
Form1.Caption 是用来设置窗体标题的,因此Form1.Caption=temp
sort arr2(),排序方法是对arr2()排序,但是程序中并没有给arr2赋值 arr2的初始值全为0 因此要先给arr2赋值
arr2(i) = arr1(i)

这个还需要解释...

'第一个问号内容
arr2(i)=arr1(i)

'第二个问号内容
Form1.Caption =temp