geojf3
geojf3

Reputation: 49

How can multiple variable be passed from VBS to batch script?

I have the following .bat file being used to run a series of jobs to:

  1. run a vbs script to calculate the previous weeks dates for Monday and Saturday
  2. run a series of commands with the dates calculated to extract data from a commercial finance application
  3. run a vbs script to load and run an Excel macro

The first part of the batch file is as follows:

echo off
rem Get last weeks Monday-Saturday dates
for /F %%n in ('cscript.exe //nologo GetLastWeek.VBS') do set LastWeek=%%n

GetLastWeek.vbs is as follows:

GetThisMonday = DateSerial(Year(Date), Month(Date), Day(Date) - DatePart("w", Date) + 1)
GetThisMonday=DateAdd("d",+1,GetThisMonday)
GetLastMonday=DateAdd("ww",-1,GetThisMonday)
GetLastSaturday=DateAdd("d",+6,GetLastMonday)
wscript.echo GetLastMonday

This will work fine for returning 1 date (GetLastMonday), but I also need the second date (GetLastSaturday).

What do I need to do to pass both values back to the bat file?

Thank you.

Upvotes: 0

Views: 296

Answers (2)

Compo
Compo

Reputation: 38604

Here's one example of how I may do it in a :

<!-- :
@Echo Off
For /F "Tokens=1,2Delims=," %%G In ('^""%__AppDir__%cscript.exe" //NoLogo "%~f0?.wsf"^"'
)Do Set "LastMon=%%G"&Set "LastSat=%%H"
Rem Rest of code below here.
Set LastMon
Set LastSat
Pause
Rem No more code below here.
Exit /B
-->
<Job><Script Language="VBScript">
    WScript.Echo(Date-Weekday(Date,vbTuesday)&","&Date-Weekday(Date,vbSunday))
</Script></Job>

Upvotes: 1

geojf3
geojf3

Reputation: 49

Someone previously made a comment here and then for some reason deleted it - but it go me thinking and trying some things I did not think of before. The following changes seem to work for what I was looking for:

wscript.echo GetLastMonday & "," & GetLastSaturday

for /f "tokens=1,2 delims=," %%A in ('cscript //nologo lastweek.vbs') do @echo %%A %%B 

Upvotes: 0

Related Questions