У меня есть обработчик событий Sub, который прослушивает ответное сообщение от Bloomberg API и сохраняет его в массиве Dd.
Согласно MSDN, обработчики событий должны быть подчиненными, но я хотел бы провести дополнительный анализ данных в моем основном методе.
Как я могу сослаться на массив, созданный в обработчике событий, чтобы продолжить обработку данных?
Обработчик события:
Private Sub session_ProcessEvent(ByVal obj As Object)
On Error GoTo errHandler
Dim eventObj As blpapicomLib2.Event
Set eventObj = obj
If Application.Ready Then
If eventObj.EventType = PARTIAL_RESPONSE Or eventObj.EventType = RESPONSE Then
Dim it As blpapicomLib2.MessageIterator
Set it = eventObj.CreateMessageIterator()
Dim numResponse As Integer
numResponse = 0
Dim data() As Variant
Do While it.Next()
numResponse = numResponse + 1
Dim msg As Message
Set msg = it.Message
Dim securityData As Element
Dim securityName As Element
Dim fieldData As Element
Set securityData = msg.GetElement("securityData")
Set securityName = securityData.GetElement("security")
Set fieldData = securityData.GetElement("fieldData")
Sheet1.Cells(currentRow, 4).Value = securityName.Value
Dim numDates As Integer
Dim numFields As Integer
numDates = fieldData.NumValues
numFields = fieldData.GetValue(0).NumElements
ReDim data(numDates, numFields, numResponse)
Dim b As Integer
For b = 0 To numDates - 1
Dim fields As blpapicomLib2.Element
Set fields = fieldData.GetValue(b)
Dim a As Integer
For a = 0 To numFields - 1
Dim field As Element
Set field = fields.GetElement(a)
data(b, a, numResponse) = field.Value
Sheet1.Cells(currentRow, a + 5).Value = data(b, a, numResponse)
Next
currentRow = currentRow + 1
Next b
Loop
' skip a row for next security
currentRow = currentRow + 1
End If
End If
Exit Sub
errHandler:
MsgBox Err.Description
End Sub
... и суб, я хотел бы обработать массив здесь...
Public Sub RefDataExample()
' Calculate the number of securities and fields
Dim numSecurity As Integer
Dim numFields As Integer
numSecurity = 0
numFields = 0
' clear data area
Range("D4", "H60000").Clear
Do While Cells(numSecurity + 4, 1).Value <> ""
numSecurity = numSecurity + 1
Loop
Do While Cells(numFields + 4, 2).Value <> ""
numFields = numFields + 1
Loop
Dim sSecurity() As String
Dim sFields() As Variant
ReDim sSecurity(0 To numSecurity - 1) As String
ReDim sFields(0 To numFields - 1) As Variant
Dim i As Integer
For i = 0 To numSecurity - 1
sSecurity(i) = Cells(i + 4, 1).Value
Next i
For i = 0 To numFields - 1
sFields(i) = Cells(i + 4, 2).Value
Next i
bbControl.MakeRequest sSecurity, sFields
'Process response array here
End Sub