我正在为学校制作一个涉及创建彩票的程序,但出于某种原因,我的代码“SubRunLottery()”的第一行返回了一个类型不匹配错误?
Sub RunLottery()
' Create requiredCards counter
Dim requiredCards(9) As Variant
' Outer For loop, 100 trials
For x = LBound(requiredCards) To UBound(requiredCards)
' Create winning numbers
Dim winLotto(3) As Variant
' Enter For loop that decides the four numbers
For n = 0 To 3
Dim w As Integer
w = CInt(Round(WorksheetFunction.RandBetween(0, 9), 0))
winLotto(n) = w
Next n
' Create win condition for Do loop
Dim winCon As Boolean
winCon = False
' Create counter to track card amount
Dim counter As Integer
Do Until winCon = True
' Create lottery card array
Dim cardLotto As Variant
' For loop to generate card
For c = 0 To 3
Dim d As Integer
d = CInt(Round(WorksheetFunction.RandBetween(0, 9), 0))
cardLotto(c) = d
Next c
' Checks if the cardLotto and winLotto arrays are the same
If cardLotto = winLotto Then
winCon = True
Else
' Increase counter if arrays are not the same
counter = counter + 1
End If
Loop
' Input the counter amount into the array
requiredCards(x) = counter
Next x
' Loop to input array values into cells
For arr = LBound(requiredCards) To UBound(requiredCards)
Sheet1.Cells(arr) = requiredCards(arr)
Next arr
End Sub
错误消息ss
错误突出显示ss
我真的不知道该在这里尝试什么,因为我不知道Excel为什么会抛出错误?我以前处理过类型不匹配,但从未在我的程序的Sub部分处理过,所以我不确定解决方案是什么。