1

I have two files: batch.bat and vbscript.vbs. The .bat file contains a loop where I need to call the .vbs, passing to it 2 arguments. The .vbs file contains a function with 2 arguments( the arguments I am passing to the .vbs file). I need to have access in the .bat file to the value my function in .vbs returns.
Could someone help me, please?

I am not an expert so please excuse my poor syntax. I am calling the .bat file. The files should look something like this

batch.bat :

loop start

' calling the vbs file

cscript vbscript.vbs arg1 arg2 ( here I suppose something has to be add to get val from vbs)

' using value returned by .vbs function

loop end 

vbscript.vbs :

function myfunction(arg1,arg2)
dim value

' do some calculation

myfunction= value
end function

dim value_to_return_to_batch
' now calling the function
value_to_return_to_batch=myfunction(arg1,arg2)
'
' here something has to be add to send value_to_return_to_batch  to batch
'
user2622509
  • 117
  • 1
  • 2
  • 11

2 Answers2

7

UPDATED

Ok, so you need to return a non-integer. The code below will work for non-integers as well as text.

This is an example, you will need to modify it to fit your needs.

In your VB Script, do this:

WScript.Echo 99.99999

In your batch file, do this:

FOR /F "usebackq tokens=*" %%r in (`CSCRIPT "MyVBS.vbs"`) DO SET RESULT=%%r
ECHO %RESULT%
aphoria
  • 19,796
  • 7
  • 64
  • 73
  • It's not an integer unfortunately. It is a real number. – user2622509 Jul 26 '13 at 12:19
  • Can you show us the full (or least relevant) portion of your actual VB Script? That message indicates that the VB Script is not writing anything to the screen, so `RESULT` does not get set to anything. Then, the `ECHO` command runs with no parameter, which gives you that message. – aphoria Jul 26 '13 at 12:41
-3

How about using an environment variable as an interface between your batch file and vbscript file parameter passing?

MansoorShaikh
  • 913
  • 1
  • 6
  • 19