Я хотел бы передать объект Scripting.Dictionary для Application.OnTime. Проблема в том, что я продолжаю получать «Ошибка компиляции: аргумент не факультативен».Передача словаря в Application.OnTime
Структура кода заключается в следующем:
Public Sub mainSub()
Dim orderBookIndex As New Scripting.Dictionary
Dim contractIndex As New Scripting.Dictionary
Call computeStuff(0, orderBookIndex, contractIndex)
End Sub
mainSub называет computeStuff, то computeStuff называет «callLive», чтобы запустить себя каждый второй после того, как увеличивается.
Public Sub computeStuff(index As Integer, Optional orderBookIndex As Scripting.Dictionary, Optional contractIndex As Scripting.Dictionary)
' Do stuff
If index = 0 Then
Set orderBookIndex = New Scripting.Dictionary
Set contractIndex = New Scripting.Dictionary
End If
If index = 1 Then
Set orderBookIndex = New Scripting.Dictionary
Set contractIndex = New Scripting.Dictionary
orderBookIndex.add "a", "b" ' add random stuff
contractIndex.add "c", "d" ' add random stuff
End If
Call callLive(index, orderBookIndex, contractIndex)
End Sub
Тогда callLive называется и отказывается компилировать:
Public Sub callLive(index As Integer, Optional orderBookIndex As Scripting.Dictionary, Optional contractIndex As Scripting.Dictionary)
Dim SchTime As Double
SchTime = Now + TimeSerial(0, 0, 1)
index = index + 1
Application.OnTime SchTime, "'computeStuff """ & index & """ ,""" & orderBookIndex & """ ,""" & contractIndex & """'", , False
End Sub
Любая помощь или руководство для достижения этой задачи (или решить эту проблему) будут высоко оценены.
Обычно рекомендуется держать глобальные переменные в минимальном использовании, но, почему бы не попробовать: сделать переменные словаря orderbookIndex 'и 'contractIndex'? –