I have a VBS script that connects to a FoxPro database.
Dim oCN : Set oCN = CreateObject("ADODB.CONNECTION")
oCN.Open sCS
Dim oRS : Set oRS = oCN.Execute("SELECT SN_ANALSYS, SN_CRLIM, SN_CURRBAL FROM " & WScript.Arguments(0) & "_SNAME.DBF WHERE SN_ANALSYS != '' ORDER BY SN_ANALSYS ASC")
Do Until oRS.EOF
WScript.Echo oRS.Fields(0).value, "50", oRS.Fields(1).Value
WScript.Echo oRS.Fields(0).value, "51", oRS.Fields(2).Value
oRS.MoveNext
Loop
oCN.Close
I run it via a BAT:
C:\query.vbs A > \\share\results.txt
The A
is used in the query (WScript.Arguments(0)
). However I want to be able to do this:
C:\query.vbs A,D > \\share\results.txt
So that it runs 2 queries using A
and D
but the results go to the same results.txt
.
Looping statements are used to run the same block of code a specified number of times. In VBScript we have four looping statements: For... Next statement - runs code a specified number of times.
There is no "Continue" in VBScript. Unfortunately VBScript does not have a "continue" statement that works in For or For Each loops. You will need to use an If statement to skip the rest of your loop. VBScript does, however, have the Exit For statement to exit from a For or For Each loop.
Use the WScript.Arguments.Unnamed
collection.
Dim arg
For Each arg in WScript.Arguments.Unnamed
' use arg in the SQL query
Next
and call without a comma, so that cmd.exe recognizes them as separate arguments:
C:\query.vbs A D > \\share\results.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With