不用放标签,一个picturebox,5个按钮
代码如下
Dim a%(1 To 10)
Private Sub Command1_Click()
Picture1.Print "产生的一维数组为:"
For i = 1 To 10
a(i) = Int(Rnd * 90 + 10)
Picture1.Print a(i);
Next i
Picture1.Print
End Sub
Private Sub Command2_Click()
Dim n%, m%
n = a(1)
m = 1
For i = 2 To 10
If a(i) > n Then n = a(i): m = i
Next i
Picture1.Print
Picture1.Print "第" & m & "个元素" & a(m) & "为最大值"
End Sub
Private Sub Command3_Click()
Dim aver#, sum#
For i = 1 To 10
sum = sum + a(i)
Next i
aver = sum / 10
Picture1.Print
Picture1.Print "产生的随机数的平均值为:" & aver
End Sub
Private Sub Command4_Click()
Dim t%
For i = 1 To 10
For j = 1 To 9
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
Picture1.Print
Picture1.Print "排序后的一维数组为:"
For i = 1 To 10
Picture1.Print a(i);
Next i
Picture1.Print
End Sub
Private Sub Command5_Click()
Dim x%, y%, b%(1 To 11)
Picture1.Print
x = InputBox("请输入要插入的数")
For i = 1 To 10
If a(i) > x Then
y = i
Exit For
End If
Next i
For i = 1 To y - 1
b(i) = a(i)
Next i
b(y) = x
For i = y + 1 To 11
b(i) = a(i - 1)
Next i
Picture1.Print "插入后的一维数组为:"
For i = 1 To 11
Picture1.Print b(i);
Next i
End Sub
Private Sub Form_Load()
Command1.Caption = "产生随机数"
Command2.Caption = "求最大值"
Command3.Caption = "求平均值"
Command4.Caption = "升序排序"
Command5.Caption = "插入新数据"
Form1.Caption = "数组应用实例"
End Sub
运行结果如下