例如有10个变量 a(1 to 10) ,如果这些变量中含有相同的数,则返回一个Boolean“真”信号。没有的话不返回。

解决方案 »

  1.   

    dim b as long 
    dim flag as booleanflag = false
    for i = 0 to 9
        b = a(i)
        for j = 0 to 9
            if j <> i then
                if a(j) = b then
                   flag = true  
                   exit for
                end if
            end if
        next j
    next i
      

  2.   

    函数代码:
    Private Function test(InputAry As Variant) As Boolean
        Dim i As Integer, j As Integer
        test = True
        For i = LBound(InputAry) To UBound(InputAry) - 1
            For j = i + 1 To UBound(InputAry)
                If InputAry(i) = InputAry(j) Then Exit Function
            Next
        Next
        test = False
    End Function调用举例:
    Dim a(0 To 9) As Integer
    Dim i As Integer
    For i = 0 To 9
        a(i) = Int(Rnd() * 30)
        Debug.Print a(i);
    Next
    Debug.Print test(a)结果输出(三次执行调用举例代码结果) 23  8  7  14  7  10  1  14  6  25 True
     17  22  27  9  16  2  19  12  28  3 False
     27  18  10  4  14  6  29  3  0  10 True