2

I have the following code:

Dim request, oXMLHttp, url
url = "WEBSITE"

request = "<?xml version='1.0' encoding='utf-8'?>" & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soap:Body>" & _
"<CheckItems xmlns=""OTHERWEBSITE"">" & _
"<ItemsNumbers>" & _
"<string >1</string>" & _
"<string >2</string>" & _
"<string >3</string>" & _
"</Items>" & _ 
"<LicenseKey>KEY</LicenseKey>" & _
"</CheckItems>" & _
"</soap:Body>" & _
"</soap:Envelope>"

Set oXMLHttp = CreateObject("MSXML2.ServerXMLHTTP")
oXMLHttp.open "POST", url, False
oXMLHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXMLHttp.send request
response = oXMLHttp.responseText

Set objFSO=CreateObject("Scripting.FileSystemObject")

outFile="C:\Path\Test.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write oXMLHttp.responseText
objFile.Close

The issue is that rather than 3 items I have say, 500 items, and running it this way causes a timeout. One suggestion to fix this is to instead set up a loop so that I instead have:

Dim request, oXMLHttp, url
url = "WEBSITE"

items = (1,2,3,4...n)

for Each item in items:

request = "<?xml version='1.0' encoding='utf-8'?>" & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soap:Body>" & _
"<CheckItems xmlns=""OTHERWEBSITE"">" & _
"<ItemsNumbers>" & _
"<string >item</string>" & _
"</Items>" & _ 
"<LicenseKey>KEY</LicenseKey>" & _
"</CheckItems>" & _
"</soap:Body>" & _
"</soap:Envelope>"

Next item

The problem is, as you might be able to see, I don't know how to set up a loop properly at all. How can I modify this code so that the loop properly executes and so that each iteration is posted to the .txt file as in the first code example? Thanks for any and all help!

UPDATE: I also receive the error 800A03EE "Expected ')'" when trying to create an array. I'm not sure where it wants the additional right bracket.

items = ("A",
"B",
"C",
...,
"Z")
4
  • 1
    I'm quite certain that you can find a VB.Net tutorial that explains how to write a for loop. Have you looked for one? Loops are very basic programming structures. Commented Feb 23, 2016 at 4:08
  • @KenWhite My concern is just that I'm not even too familiar with what the code I have is doing, I just have a vague idea, so I'm not sure where to actually begin and end the for loop. Have I set it up properly above or does Next need to be below response = oXMLHttp.responseText for example? Commented Feb 23, 2016 at 4:16
  • When in doubt, read the documentation. We do expect that you have at least a basic understanding of the language you're using. We're not here to provide you with language tutorials. Commented Feb 23, 2016 at 13:35
  • @ansgarWiechers Understandable, but I do believe I've made a good faith attempt to use the documentation with my proposed loop implementation above. Commented Feb 23, 2016 at 18:17

1 Answer 1

1

Try this:

items = Array(1,2,3,4,"za")
myitems=""

For Each item in items
  myitems = myitems & "<string >" & item & "</string>"
Next

request = "<?xml version='1.0' encoding='utf-8'?>" & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""     xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soap:Body>" & _
"<CheckItems xmlns=""OTHERWEBSITE"">" & _
"<Items>" & myitems & "</Items>" & _ 
"<LicenseKey>KEY</LicenseKey>" & _
"</CheckItems>" & _
"</soap:Body>"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.