Option Explicit
Dim i As Integer,j As Integer'用于数组的变量
Dim Temp As Integer '保存随机数的容器
Dim Flag As Boolean '判断生成的数是废掉还是保存
Dim k As Integer '生成的数的个数K
Dim m As Integer '生成数的范围的下界M
Dim n As Integer '生成数的范围的上界N
Dim max As Integer '进行最大值判断的变量
Dim p As String
Private Sub Command1_Click()
k = Val(Text1.Text)
n = Val(Text2.Text)
m = Val(Text3.Text)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ReDim a(0 To k) '定义一个数组范围从0到k
Randomize
For i = 0 To k
Flag = False 'flag的默认初值是false
If Temp = a(j) Then
i = i - 1
Flag = True
Exit For
End If
Next j
If Flag = False Then
a(i) = Temp
If i = k Then
Print a(i) & Chr(13) & Chr(10)
Else
Print a(i);
End If
End If
Next i
'‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
'大小的比较
max = a(0)
'把产生的第一个数a(0)视为最大的数
For i = 1 To k '如果后面的数大于max则把这个数付给max
If max < a(i) Then
max = a(i)
End If
Label1.Caption = Str(max)
End Sub