Reputation: 181
I'm wondering if it is possible to add a comma between values in VBscript so that it is formatted correctly in .csv files.
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load ("C:\Users\c1921\Ayla_Data\TestFile.xml")
Set colNodes = xmlDoc.SelectNodes _
("/datapoints/datapoint/(updated-at | value)")
For Each objNode In colNodes
Wscript.Echo objNode.Text
Next
If updated-at
is a time value and value
is a data value then I would like one to be in column A and another in column B. Is this easily done?
I can't seem to find any references for how to do this. I'm wondering if something like this line might work(It gives me a syntax error):
Wscript.Echo & "," objNode.Text
EDIT
Going off of what Ekkehard.Horner said the amended code looks like this:
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load ("C:\Users\c1921\Ayla_Data\TestFile.xml")
Set colNodes = xmlDoc.SelectNodes _
("/datapoints/datapoint/(updated-at | value)")
mystringout = ""
mystringnext = False
For Each objNode In colNodes
If mystringnext= False then
mystringout = mystringout & objNode.Text & ","
mystringnext= True
Else
mystringout = mystringout & objNode.Text & vbCrLf
mystringnext = false
End If
Next
WScript.Echo mystringout
Upvotes: 0
Views: 1942
Reputation: 38745
Either use the concatenation operator correctly (x & y), or Join (which scales much better):
>> av = "ColAVal"
>> bv = "ColBVal"
>> WScript.Echo av & "," & bv
>> a = Array(av, bv)
>> WScript.Echo Join(a, ",")
>>
ColAVal,ColBVal
ColAVal,ColBVal
Upvotes: 1