2013-04-17 4 views
2

Все, Следующий код из Bloomberg. Он предназначен для извлечения массивных данных со своих серверов. Код работает, но я пытаюсь извлечь определенную переменную, сгенерированную в модуле класса, и привести ее в обычный модуль для пользовательских функций. Спасибо за помощь.Извлечение определенной переменной из модуля класса в VBA в стандартный модуль

Option Explicit 
Private WithEvents session As blpapicomLib2.session 
Dim refdataservice As blpapicomLib2.Service 

Private Sub Class_Initialize() 
Set session = New blpapicomLib2.session 
session.QueueEvents = True 
session.Start 
session.OpenService ("//blp/refdata") 
Set refdataservice = session.GetService("//blp/refdata") 
End Sub 

Public Sub MakeRequest(sSecList As String) 
Dim sFldList As Variant 
Dim req As Request 
Dim nRow As Long 
sFldList = "CALL_SCHEDULE" 
Set req = refdataservice.CreateRequest("ReferenceDataRequest") 'request type 
req.GetElement("securities").AppendValue (sSecList) 'security + field as string array 
req.GetElement("fields").AppendValue (sFldList) 'field as string var 
Dim cid As blpapicomLib2.CorrelationId 
Set cid = session.SendRequest(req) 
End Sub 

Public Sub session_ProcessEvent(ByVal obj As Object) 
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() 
     Do While it.Next() 
      Dim msg As Message 
      Set msg = it.Message 
       Dim Security As Element 
       Set Security = msg.GetElement("securityData").GetValue(0) 
       Sheet1.Cells(4, 4).Value = Security.GetElement("security").Value 
       Dim fieldArray As Element 
       Set fieldArray = Security.GetElement("fieldData") 
        Dim field As blpapicomLib2.Element 
        Set field = fieldArray.GetElement(0) 
        If field.DataType = 15 Then 
         Dim numBulkValues As Long 
         numBulkValues = field.NumValues '76 
         Dim index As Long 
         For index = 0 To numBulkValues - 1 
          Dim bulkElement As blpapicomLib2.Element 
          Set bulkElement = field.GetValue(index) 
          Dim numBulkElements As Integer 
          numBulkElements = bulkElement.NumElements '2 elements per each pt 
          ReDim Call_Sch(0 To numBulkValues - 1, 0 To numBulkElements - 1) As Variant 
          Dim ind2 As Long 
          For ind2 = 0 To numBulkElements - 1 
           Dim elem As blpapicomLib2.Element 
           Set elem = bulkElement.GetElement(ind2) 
           Call_Sch(index,ind2)=elem.Value 
           Sheet1.Cells(index + 4, ind2 + 5) = elem.Value 
          Next ind2 
         Next index 
        Else 
        Call_Sch(index,ind2)=field.Value  
        Sheet1.Cells(index + 4, ind2 + 5).Value = field.Value 
        End If 
     Loop 
    End If 
End If 
End Sub 

Переменная, которую я пытаюсь получить, в частности, является Call_Sch. Я хочу, чтобы функция в основном модуле распознавала переменную. Еще раз спасибо.

+2

Для того, чтобы значение в классе видимой снаружи, вы сделаете это свойство, как в этом примере : http://stackoverflow.com/questions/5342666/vba-array-of-variant-type-as-class-property Или вы можете просто сделать свой массив общедоступным. Но, похоже, вы не разместили весь свой код, так как нет кода, который объявляет 'Call_Sch' в любом месте - только ReDim. –

ответ

0

Нет необходимости объявлять переменную перед использованием ReDim; ReDim может объявить переменную. Тем не менее, если вы добавили:

Public Call_Sch() as Variant ' Insert correct data type here 

тогда вы могли бы обратиться к нему с помощью:

<YourClassVaraibleName>.Call_Sch