我很难将变量传递给函数。我放入函数的变量名可能会有所不同,因此我使用了另一个变量“x”。 我错过了什么? “myVar”简单地不等于数组名称(例如arrNames(2)= Nancy)我传入函数。
Public Const intContestants = 7
Public intRandom, myVar, x As Integer
Public Function arrContestants(x As Integer) As String
ReDim arrNames(0 To intContestants) As Variant
'set contestant names to assingments in array
arrNames(0) = "Kathleen "
arrNames(1) = "Bruce "
arrNames(2) = "Nancy"
arrNames(3) = "Katherine"
arrNames(4) = "Debra"
arrNames(5) = "Glenn"
arrNames(6) = "Andrew"
arrNames(7) = "Willy"
myVar = arrContestants(x)
End Function
Public Sub Roll()
intRandom = Int((intContestants - 0 + 1) * Rnd + 1)
myVar = arrContestants(intRandom)
ActivePresentation.Slides(1).Shapes("Contestant").OLEFormat.Object.Value = myVar
End Sub
答案 0 :(得分:0)
我猜测而不是这一行:
myVar = arrContestants(x)
你的意思是:
arrContestants = arrNames(x)