很完美
Dim M(49) As Integer,N() As Integer
'判断某元素是否属于某数组
Function cf(B() As Integer,nn As Integer) As Boolean 'B()为数组,nn为元素
On Error Resume Next '防止空数组
For Each v In B
If v = nn Then cf = True:Exit For
Next v
End Function
Private Sub Command1_Click()
Dim m1 As Integer,n1 As Integer 'm1存放M()随机下标,n1存放N()上届
'初始化数组a(),1-50
For i = 0 To 49
M(i) = i + 1
Next i
'初始化集合N
Do
Randomize '随机
m1 = M(Int(50 * Rnd)) '生成M()随机下标
If cf(N(),m1) = flase Then '防止N()元素重复
ReDim Preserve N(n1) '重置数组长度
N(n1) = m1 '新元素赋值
n1 = n1 + 1 '数组上届变量加1
End If '结束判断
Loop While UBound(N) < 24 '循环语句块结束
'输入六个数字
Dim k As Integer '存放输入数字
For j = 1 To 6
k = Val(InputBox("请输入6个数字,第" & j & "个数字"))
If cf(N(),k) = False Then '不属于
'输出集合N()
For Each v In N
Print v & ",";
Next v
Print '换行
MsgBox (k & "不属于集合N()")
Else '属于
MsgBox (k & "属于集合N()")
End If
Next j
End Sub
由于你的要求有点歧义,这里假定是判断6个数字中每个数字是否属于集合N,而不是判断是否全部属于,当然,这都是次要的,主要部分的代码已给出,可以自己改.
注:任取25个数还有一种方法是先给M随机排序,再顺序输出25元素,皆可