Command-line with Web Services and Arguments


I added the small feature of being able to pass an argument to the Stock.vbs file so you can pass it any stock quote.

My Stock.vbs file is:

set SOAPClient = createobject("MSSOAP.SOAPClient")
SOAPClient.mssoapinit "
http://www.webservicex.net/stockquote.asmx?WSDL"
WScript.Echo wscript.arguments(0) & " = " & SOAPClient.GetQuote(wscript.arguments(0))

The part in bold is the change from a previous post that allows the argument. To run it, from a command line, run:

C:\>Stocks.vbs MSFT

 

Comments (1)
  1. You can make the output more readble using:

    Dim responseEnv

    Dim displayStr

    Set responseEnv = CreateObject("MSXML2.DOMDocument.3.0")

    responseEnv.loadXML(SOAPClient.GetQuote(wscript.arguments(0)))

    ‘MsgBox responseEnv.xml

    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))

    Set responseEnv = Nothing

Comments are closed.

Skip to main content