Issue
I am trying to perform a SOAP call but sometimes the response is thousands of record. I don't want Excel frozen while it is processing the responses but every example I've seen require importing a separate file with the async callback. Is there a way I can do this without the extra file?
Public Function SendPost(currentTableAltIden As String, altIdentifiers() As String, Optional aSync As Boolean = True)
Dim t As XMLHTTP60
Dim r As MSXML2.DOMDocument60
Dim nodeList As IXMLDOMNodeList
Dim i As Integer
Dim listLengthControl As Integer
Dim listCounter As Integer
Dim xmlHelper As AsyncHelper
i = 0
Set t = Transport
Set xmlHelper = New AsyncHelper
xmlHelper.init t
t.Open "POST", EndPointUrl, aSync
t.send Text
Set r = New MSXML2.DOMDocument60
r.aSync = False
r.validateOnParse = False
r.SetProperty "SelectionNamespaces", " xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"
r.LoadXML t.responseText
Set nodeList = r.SelectNodes("//result//" & currentTableAltIden)
listLengthControl = nodeList.Length
While listCounter <> listLengthControl
For i = LBound(altIdentifiers) To UBound(altIdentifiers)
Debug.Print r.SelectNodes("//result//" & currentTableAltIden & "//" & altIdentifiers(i))(listCounter).Text
WorkWebServiceTemp.Cells(TableDataRowNum + listCounter, i + 1).value = r.SelectNodes("//result//" & currentTableAltIden & "//" & altIdentifiers(i))(listCounter).Text
Next i
listCounter = listCounter + 1
Wend
End Function
Solution
Just for fun...
Sub AsyncTester()
Static col As Collection
Set col = New Collection
col.Add AsyncFetcher("https://stackoverflow.com/", New clsTest)
col.Add AsyncFetcher("https://google.com/", New clsTest)
col.Add AsyncFetcher("https://news.ycombinator.com/", New clsTest)
Debug.Print "finished setup"
End Sub
Function AsyncFetcher(url As String, callBackObject As Object)
Dim sc As Object
Set sc = CreateObject("MSScriptControl.ScriptControl")
sc.Language = "JScript"
sc.AddCode "var objXML, theUrl, objCallBack;"
sc.AddCode " function callBack(){objCallBack.Report(objXML.readystate + ' ' + theUrl);} " & vbLf
sc.AddCode " function fetch(url, obj){ " & vbLf & _
" objCallBack = obj; theUrl = url; " & vbLf & _
" objXML = new ActiveXObject('Msxml2.XMLHttp.6.0'); " & vbLf & _
" objXML.onreadystatechange = callBack; " & _
" objXML.open(""GET"", url, true); " & vbLf & _
" objXML.send(); " & vbLf & _
"} "
sc.Run "fetch", url, callBackObject
Set AsyncFetcher = sc
End Function
clsTest:
Public Sub Report(s)
Debug.Print s
End Sub
Answered By - Tim Williams Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.