Excel VBA功能 - 获取运行时错误' 91'使用角色

时间:2015-07-05 20:18:45

标签: excel-vba vba excel

以下是我的功能代码:

Function ValuSuit(Card As Integer) As Characters

    Dim divCard As Integer
    Dim modCard As Integer

    Dim Values(1 To 13) As String
    Dim Suits(1 To 4) As String

    Dim TempChar As Characters

    Values(1) = "A"
    Values(2) = "2"
    Values(3) = "3"
    Values(4) = "4"
    Values(5) = "5"
    Values(6) = "6"
    Values(7) = "7"
    Values(8) = "8"
    Values(9) = "9"
    Values(10) = "10"
    Values(11) = "J"
    Values(12) = "Q"
    Values(13) = "K"

    Suits(1) = "S"
    Suits(2) = "H"
    Suits(3) = "D"
    Suits(4) = "C"

    divCard = Application.RoundUp((Card / 13), 0)
    modCard = Card Mod 13

    If modCard = 0 Then
        TempChar = "K"
    Else
        TempChar = Values(modCard)
    End If
    ValuSuit = TempChar & Suits(divCard)
End Function

TempChar = Values(modCard)行引发错误。我最初将Values和Suits变量声明为Characters,但这导致了Values(1) = "A"行的错误。一些研究表明String是更好的选择。非常感谢任何帮助。

0 个答案:

没有答案