用0到100之内的数组做了一个,最小值,最大值检索.源码如下-
'------------------'------------------'------------------'------------------'------------------
Option Explicit
Dim intSums1(19) As Integer '数组
'生成随机数 [生成按钮]
Private Sub Command2_Click()
Dim ctr As Control '控件对象
For Each ctr In Controls '初始化TextBox控件(3个)
If TypeOf ctr Is TextBox Then ctr.Text = ""
Next ctr
Dim intCount As Integer '循环变量
For intCount = 0 To 19
Randomize '初始化随机数生成器
intSums1(intCount) = Int(100 * Rnd) ' 生成 0 到 100 之间的随机数
Text3.Text = Text3.Text & intSums1(intCount) & ","
Next intCount
End Sub
'计算的事件处理 [计算按钮]
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
j = 0 '-----------------<找最小值>----------------
Do '从0开始到100
For i = 0 To 19 '20个数组
If j = intSums1(i) Then Text1.Text = intSums1(i): Exit Do '最小值
Next i
j = j + 1
Loop
j = 100 '-----------------<找最大值>----------------
Do '从100开始到0
For i = 0 To 19 '20个数组
If j = intSums1(i) Then Text2.Text = intSums1(i): Exit Do '最大值
Next i
j = j - 1
Loop
End Sub
'关闭按钮
Private Sub Command3_Click()
Unload Me
End Sub
'------------------'------------------'------------------'------------------'------------------