Using VBScript functions from TCC22

I am a frequent user of VBScript, and have added the following to TCC22 to make using VBScript functions easier;

I have created a library file;
Code:
vb {
@setlocal
@echo off
echo set fso=CreateObject("Scripting.FileSystemObject") > c:\utils\vb.vbs
echo set stdout=fso.GetStandardStream(1) >> c:\utils\vb.vbs
echo stdout.WriteLine %* >> c:\utils\vb.vbs
echo set fso=Nothing >> c:\utils\vb.vbs
cscript //nologo c:\utils\vb.vbs
if exist c:\utils\vb.vbs del /q c:\utils\vb.vbs
endlocal
}

...which I load via my 4Start.btm (TCStart.btm) file as;
Code:
if exist c:\utils\vb.library library /r c:\utils\vb.library

I have also defined a function in my function.lst file as;
Code:
vb=%@execstr[vb %$]

...which I load via my 4Start.btm (TCStart.btm) file as;
Code:
if exist function.lst function /r function.lst

Now, I can use a single VBScript function, for example;
Code:
c:\users\jlc\utils>vb FormatCurrency(1000)
$1,000.00

..or

Code:
c:\users\jlc\utils>echo %@vb[FormatCurrency(1000)]
$1,000.00

Other examples;
Code:
vb FormatPercent(2/32)
6.25%

vb DateAdd("m", 1, "30-Nov-2017")
12/30/2017

vb MonthName(11)
November

vb MonthName(11, True)
Nov

vb DateDiff("d", "12/25/1955", Now) / 365.25
61.9329226557153

Joe
 
I've updated the VB function in my library to no longer use the external CScript.exe, but instead use the internal Script command, and the tcommand() interface.
Code:
vb {
@setlocal
@echo off
:: Disable the Escape Character
setdos /X-8
if %1 eq help (
  echo vb 140.97*52
  echo vb dateadd("m", 708, "01-Nov-1960")
  echo vb DateDiff("d", "11/01/1960", Now) / 365.25
  quit
)
set dest=%temp\vb.vbs

>%dest echo result=%*
>>%dest echo TakeCommand.tcommand("echo " + CStr(result))

set _vb=%@execstr[script %dest]

echo %_vb

endlocal _vb
}
Examples;
Code:
e:\utils>vb 140.97*52
7330.44

e:\utils>vb dateadd("m", 708, "01-Nov-1960")
2019-11-01

e:\utils>vb DateDiff("d", "11/01/1960", Now) / 365.25
61.1498973305955

e:\utils>echo %_vb
61.1498973305955

Joe
 
Aug 23, 2010
678
9
Code:
vb {
@SETLOCAL
@ECHO OFF
REM Disable the Escape Character
SETDOS /X-8
IF "%~1" EQ "help" (
  ECHO vb 140.97*52
  ECHO vb dateadd("m", 708, "01-Nov-1960")
  ECHO vb DateDiff("d", "11/01/1960", Now) / 365.25
  QUIT
)
SET _vbs=%@UNIQUE[%[TEMP],vbs-]

>%[_vbs] ECHO result=%*
>>%[_vbs] ECHO TakeCommand.tcommand("echo " + CStr(result))

SET _vb=%@EXECSTR[SCRIPT "%[_vbs]"]

ECHO %[_vb]

DEL /QE %[_vbs]

ENDLOCAL
}

smth. like dat
 

Similar threads