|
Answer» Hi...
Just to make a query here...
Is there any BETTER way to pass variable from batch to VBScript and back to batch instead of USING temp.txt? As batch cannot perform decimal point calculation, therefore i need VBScript to help up that part. As i still perfer batch coding, so dun wish to leave batch and do everything in VBScript.
I heard about pipe, but can't find much info about that. I make an example here, see anyone can help...
Set /A Total=1000 Set /A Failed=30
Need to sent these info from Batch Main.bat to VBScript PercentageCalc.vbs Then return the 3.0% back to Batch but should be as string i guess, else i will loss the .0 in batch.
My VER Microsoft Windows XP [Version 5.1.2600]Code: [Select]Dim Total,Failed,Sum Set objArgs = WScript.Arguments Total=objArgs(0) Failed=objArgs(1) WScript.Echo "Total " ,Total WScript.Echo "Failed ", Failed Sum=CDbl(Total) + CDbl(Failed ) WScript.Quit(Sum) 'or use Wscript.Echo Sum save as filename.vbs. Then invoke from batch Code: [Select]c:\> cscript /nologo filename.vbs 3000 1000 c:\> echo %ERRORLEVEL% from batch, catch the return using errorlevel ( for Quit method) . If you use the Wscript.Echo method in vbscript, see here on how to catch it in batch using for loop.Hi, thanks for your prompt reply, I have tried it with this, please correct me if i am wrong...
I have created 2 files in C:\ Directory.
Filename: Filename.vbs
Dim Total,Failed,Sum Set objArgs = WScript.Arguments Total=objArgs(0) Failed=objArgs(1) WScript.Echo "Total " ,Total WScript.Echo "Failed ", Failed Sum=CDbl(Total) + CDbl(Failed ) WScript.Quit(Sum) 'or use Wscript.Echo Sum
Filename: Filename.bat
@echo off cscript /nologo @echo off
cscript /nologo "c:\filename.vbs" 3000 1000 echo %errorlevel%
Pauses 3000 1000 echo %errorlevel% Pause
It works fine, thanks a lot. However, i have another minor issue here, If i am using a division like 1000/3000, i can't get the 33.3333... results, any clue?
For the Echo method, my code are as below,
Filename: Filename.vbs
Dim Total,Failed,Sum Set objArgs = WScript.Arguments Total=objArgs(0) Failed=objArgs(1) WScript.Echo "Total " ,Total WScript.Echo "Failed ", Failed Sum=CDbl(Total) + CDbl(Failed ) Wscript.Echo Sum
Filename: Filename.bat
@echo off for /f "tokens=*" %%i IN ('cscript /nologo c:\filename.vbs') do ( echo %%i )
Any reason why it won't work? Got this error c:\filename.vbs(3, 1) Microsoft VBScript runtime error: Subscript out of range
Quote from: simonchin79 on July 08, 2007, 09:54:56 AM However, i have another minor issue here, If i am using a division like 1000/3000, i can't get the 33.3333... results, any clue?
in which part of the script did you input 1000/3000? show how you input this.
Quote@echo off for /f "tokens=*" %%i IN ('cscript /nologo c:\filename.vbs') do ( echo %%i )
Any reason why it won't work? Got this error c:\filename.vbs(3, 1) Microsoft VBScript runtime error: Subscript out of range
the script expects input parameters, the for loop calling the script is missing those parameters. This is a good resource to read.Oops, the code which i post is not a division, here is the code i use in the vbs for the division:
Dim Total,Failed,Sum Set objArgs = WScript.Arguments Total=objArgs(0) Failed=objArgs(1) WScript.Echo "Total " ,Total WScript.Echo "Failed ", Failed FailPercentage=CDbl(Failed) / CDbl(Total) * 100 WScript.Quit(FailPercentage)
Thanks for the resources. Will read up more on the script SIDE...
|