2013-04-17 2 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