VBS and BAT parameters

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
geojf3
Posts: 1
Joined: 31 Jan 2020 14:07

VBS and BAT parameters

#1 Post by geojf3 » 31 Jan 2020 14:18

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:

Code: Select all

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:

Code: Select all

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.

penpen
Expert
Posts: 1859
Joined: 23 Jun 2013 06:15
Location: Germany

Re: VBS and BAT parameters

#2 Post by penpen » 31 Jan 2020 15:56

The following might help you (untested; are you sure your vbs is correct?).

"test.bat":

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
rem Get last weeks Monday-Saturday dates
for /F "tokens=* delims=" %%n in ('cscript.exe //nologo GetLastWeek.VBS') do set "%%~n"
set last
goto :eof
"GetLastWeek.VBS"

Code: Select all

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 "lastMonday=" & GetLastMonday
wscript.echo "lastSaturday=" & GetLastSaturday
penpen

Post Reply