Public Function GetRandom()
    Dim word() As String
    Dim MyValue As String
    word() = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
    MyValue = word(Int((UBound(word) * Rnd)))
    GetRandom = MyValue
End Function
vb的数组错哪了?

解决方案 »

  1.   

    把String改成VariantPublic Function GetRandom()
        Dim word() As Variant
        Dim MyValue As String
        word = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
        MyValue = word(Int((UBound(word) * Rnd)))
        GetRandom = MyValue
    End Function
      

  2.   

    因为Array函数的返回值是变体类型,当你试图把变体类型赋值给string类型的数组变量的时候就会类型不匹配。
      

  3.   

    数组类型改variant 或者 直接取字母 MyValue=chr(65+25*rnd)