question

Upvotes
Accepted
1 0 1 2

I am able to get real-time data using the API but I am doing something wrong when I try to get non-real-time data

Private Sub Form_Load()
    Me.WindowState = vbMaximized
End Sub
Sub Sleep_DoEvents(msg As String, Optional Milliseconds As Long = 3000)
    Dim tc As Long
    Form1.Caption = msg
    tc = GetTickCount
    While GetTickCount < tc + Milliseconds
        Sleep 1
        DoEvents
    Wend
End Sub
Private Sub cmdNonRealtime_Click()
    Dim MyEikonDDA As EikonDesktopDataAPI
    Dim MyDex2Mgr As Dex2Mgr
    Dim MyRData As Dex2Lib.RData
    Dim MyDex2Cookie As Long
    Dim MyFieldList As Variant
    Dim MyItemList As Variant
    Dim msg As String
    Dim EikonInitResult As EikonDesktopDataAPILib.EEikonDataAPIInitializeResult
    Dim Value_Returned
    Dim DataStatus As Dex2Lib.DEX2_DataStatus
    Dim MyRequestParamList As Variant
    MyFieldList = "TR.CompanyName"
    MyItemList = "GS"
    MyRequestParamList = ""
    Set MyEikonDDA = New EikonDesktopDataAPI
    msg = "Waiting after Set EikonDDA = New EikonDesktopDataAPI"
    Sleep_DoEvents msg, Milliseconds:=SLEEP_LENGTH
    EikonInitResult = MyEikonDDA.Initialize
    If EikonInitResult = Error_InitializeFail Then
        MsgBox "The result of EikonDDA.Initialize was Error_InitializeFail, end"
        End
    End If
    If EikonInitResult = Error_Reinitialize Then
        MsgBox "The result of EikonDDA.Initialize was Error_Reinitialize, end"
        End
    End If
    If EikonInitResult = Succeed Then
        MsgBox "The result of EikonDDA.Initialize was Succeed, continue"
    End If
    msg = "Waiting after EikonDDA.Initialize"
    Sleep_DoEvents msg, Milliseconds:=SLEEP_LENGTH
    If EikonInitResult = Error_InitializeFail Then
        'Handle fail case here
    ElseIf EikonInitResult = Error_Reinitialize Then
        'Handle reinitialize case here
    End If
    msg = "Waiting before EikonDDA.CreateDex2Mgr"
    Sleep_DoEvents msg, Milliseconds:=SLEEP_LENGTH
    Set MyDex2Mgr = MyEikonDDA.CreateDex2Mgr()
    msg = "Waiting after Set MyDex2Mgr = EikonDDA.CreateDex2Mgr"
    Sleep_DoEvents msg, Milliseconds:=SLEEP_LENGTH
    MyDex2Cookie = MyDex2Mgr.Initialize(DE_MC_ADC_POWERLINK)
    msg = "Waiting after MyDex2Mgr.Initialize"
    Sleep_DoEvents msg, Milliseconds:=SLEEP_LENGTH
    Set MyRData = MyDex2Mgr.CreateRData(MyDex2Cookie)
    msg = "Waiting after MyDex2Mgr.MyDex2Mgr.CreateRData"
    Sleep_DoEvents msg, Milliseconds:=SLEEP_LENGTH
    MyRData.FieldList = MyFieldList
    MyRData.InstrumentIDList = MyItemList
    MyRData.DisplayParam = "RH:In CH:Fd"
    MyRData.RequestParam = MyRequestParamList
    MyRData.Subscribe
    msg = "Waiting after MyRData.Subscribe"
    Sleep_DoEvents msg, Milliseconds:=SLEEP_LENGTH
    If MyRData Is Nothing Then
    Else
        Value_Returned = MyRData.Data(1, 1)
        ' ?err.Description
        ' Method 'Data' of object 'IRData' failed
        MsgBox Value_Returned
    End If
End Sub
eikoneikon-com-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
39.2k 75 11 27

See the answer on this thread.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
1 0 1 2

The code looked good in the preview, sorry.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
39.2k 75 11 27

Sorry, but this code is unreadable. For code snippets use the code field, which you can insert by clicking Insert Code button in the toolbar above the text editor field when writing an answer. Or attach the code as a text file. Here's an example of the code in the code field.

Private Sub Form_Load()
Me.WindowState = vbMaximized
End Sub
Sub Sleep_DoEvents(msg As String, Optional Milliseconds As Long = 3000)
Dim tc As Long
Form1.Caption = msg
tc = GetTickCount
While GetTickCount < tc + Milliseconds
    Sleep 1
    DoEvents
Wend
End Sub 

Would you mind also mentioning what problem you experienced when you run your code and where you run it? I suppose this is VBA, but what application do you run it in? Excel, other MS Office application or something else?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea