Cannot retrive data in VBA from AdxRtHistory

Hello,

I need help with AdxRtHistory.

I request data via VBA but does not wait for data to be retrieved.

With myAdxRtHist

While (.DataStatus = RT_DS_NULL_EMPTY Or .DataStatus = RT_DS_PARTIAL) And .RunStatus = RT_RS_BUSY

Wend

End With

Could you please help me make vba wait until it gets an answer from Reuters ?

Thanks a lot,

Hamza

Best Answer

  • Hi @Hamza Guedira

    VBA is single threaded. While your loop is running, it occupies the thread disallowing AdxRtHistory object to retrieve and process the data. AdfinX Real-Time API is asynchronous by design. Rather than trying to trick it into producing synchronous behavior, I would strongly advise that you follow the asynchronous pattern and split your code into the procedure that requests the data and immediately exits, and OnUpdate event callback, which will be raised once the object finished retrieving the data. See the tutorial following the link below for further details and an example.
    https://developers.thomsonreuters.com/eikon-apis/com-apis-use-microsoft-office/learning?content=3558&type=learning_material_item

    If however you must opt for synchronous data retrieval, then you need to make sure to include in the body of your loop the DoEvents statement to cede the execution thread and allow messages from Windows message queue to be processed. I would also strongly advise to implement a timeout to prevent an endless loop. Attached is a quick and dirty example. In production you will want to include a lot more error handling, as the synchronous retrieval pattern makes the example more error prone. I cannot help but wonder if the addition of timeout implementation based on an arbitrary timeout interval and extra error handling are worth whatever it is that you're trying to achieve by implementing synchronous retrieval.
    adxrthistorysynchronous.zip