I have a VBA function that is supposed to get some information from the user's cell, make a POST request with that info, then print the response in the output cell.
It's required that the user be able to make about 2000 requests at a time, so I thought to make the requests async to help improve performance.
As it stands right now, I have a function ConnectToAPI that makes the asynchronous request, then passes the response off to a callback function. The problem I'm having is that the data lives in the callback function, but I need it in the query function in order to return it.
Function Query(ID, quote, field)
Application.Volatile
Query = ConnectToAPI(ID)
Some logic with parsed data from callback
End Function
Function ConnectToAPI(ID)
Dim Request As New WebRequest
Dim Client As New WebClient
Client.BaseUrl = "http://www.endpoint.com"
Dim Wrapper As New WebAsyncWrapper
Dim Wrapper.Client = Client
Dim Body As New Dictionary
Body.Add "ID", ID
Set Request.Body = Body
Request.Method = HttpPost
ConnectToAPI = Wrapper.ExecuteAsync Request, "CallbackFunction"
End Function
Function CallbackFunction
Callback = Parsed Data
End function
So ultimately in the query function, I want to write
Query = (Parsed Data From the Callback)
How can I pass the data from the callback back up to query?
It is important that the cell have the Query function in it. The data updates frequently, so we want clients to be able to calculate the workbook to get the newest data.
With what I currently have, my thought process is that the callback will pass the data back to ConnectToAPI, then that will be passed up to Query. However, my function returns 0 and I think this might be that the parsed data is not available once the function tries to return.
For reference, I am using the VBA-Web library https://github.com/VBA-tools/VBA-Web


Event,RaiseEvent, andWithEventskeywords.