Improved Command-Line with Web Services App


Thanks to Darshan Singh from http://www.yukonxml.com/. My simple app now formats the XML before displaying it to you. Here's the code - I know I learned something from it, so hopefully you can too:

set SOAPClient = createobject("MSSOAP.SOAPClient")
SOAPClient.mssoapinit "
http://www.webservicex.net/stockquote.asmx?WSDL"
Dim responseEnv
Dim displayStr
Set responseEnv = CreateObject("MSXML2.DOMDocument.3.0")
responseEnv.loadXML(SOAPClient.GetQuote(wscript.arguments(0)))
displayStr = responseEnv.selectSingleNode("/StockQuotes/Stock/Name").nodeTypedValue
displayStr = displayStr + " (" + responseEnv.selectSingleNode("/StockQuotes/Stock/Symbol").nodeTypedValue
displayStr = displayStr + " ) " + responseEnv.selectSingleNode("/StockQuotes/Stock/Last").nodeTypedValue
displayStr = displayStr + " " + responseEnv.selectSingleNode("/StockQuotes/Stock/PercentageChange").nodeTypedValue
displayStr = displayStr + " " + responseEnv.selectSingleNode("/StockQuotes/Stock/Date").nodeTypedValue
displayStr = displayStr + " " + UCase(responseEnv.selectSingleNode("/StockQuotes/Stock/Time").nodeTypedValue)
displayStr = displayStr + VBNewLine + "-----------------------------------------------------------------------------------" + VBNewLine
displayStr = displayStr + VBNewLine + "Open: " + responseEnv.selectSingleNode("/StockQuotes/Stock/Open").nodeTypedValue
displayStr = displayStr + VBNewLine + "High: " + responseEnv.selectSingleNode("/StockQuotes/Stock/High").nodeTypedValue
displayStr = displayStr + VBNewLine + "Low: " + responseEnv.selectSingleNode("/StockQuotes/Stock/Low").nodeTypedValue
displayStr = displayStr + VBNewLine + "Volume: " + responseEnv.selectSingleNode("/StockQuotes/Stock/Volume").nodeTypedValue
displayStr = displayStr + VBNewLine + "P/E Ratio: " + responseEnv.selectSingleNode("/StockQuotes/Stock/P-E").nodeTypedValue
displayStr = displayStr + VBNewLine + "Prev. Close: " + responseEnv.selectSingleNode("/StockQuotes/Stock/PreviousClose").nodeTypedValue
displayStr = displayStr + VBNewLine + "52-Week Range: " + responseEnv.selectSingleNode("/StockQuotes/Stock/AnnRange").nodeTypedValue
displayStr = displayStr + VBNewLine + "Market Cap: " + responseEnv.selectSingleNode("/StockQuotes/Stock/MktCap").nodeTypedValue
displayStr = displayStr + VBNewLine + "-----------------------------------------------------------------------------------" + VBNewLine
MsgBox displayStr, 0, UCase(wscript.arguments(0))

From the command line, run:

C:\>Stocks.vbs MSFT

 

Comments (0)

Skip to main content