Getting type mismatch error in vbScript
Set args = WScript.Arguments
dim rec
rec = args.Item(1)&" "&args.Item(2)
return rec
I wrote this simple vbScript above and then when I try to call this code from Java ...
import java.io.*;
class RuntimeDemo{
public static void main(String[] args) {
Process p=null;
try {
p=Runtime.getRuntime().exec("wscript D:/AS/VBScripts/Sample1.vbs " + args[0] +" " + args[1] + " " + args[2]);
}
catch( IOException e ) {
System.out.println(e);
System.exit(0);
}
p.waitFor();
InputStream in = p.getInputStream();
for (int i = 0; i < in.available(); i++) {
System.out.println("" + in.read());
I am getting an error "Type mismatch 'return'"
. Where exactly is this happening and what would be the correct decision?
source to share
Your error is likely related to trying to set a "return" to a value. VBScript does not support "backtracking". If you want to return a value from a function, you must construct it like this:
function GetParams()
dim wsh, args, rec
set wsh = CreateObject("WScript.Shell")
set args = wscript.arguments
if args.Count <= 0 then
GetParams = ""
exit function
end if
if args.Count >= 2 then
rec = args(1) & " " & args(2)
elseif args.count = 1
rec = args(1)
else
rec = ""
end if
GetParams = rec
end function
In VB and vbScript, your "return value" is set by assigning a value to the function name, as I did.
Of course, you need to be careful, because if argument 2 is not passed you will get an array substring index error, so always use args.Count as I showed above before trying to access the parameters individually.
If you have a more specific question or bug, or explain what you are doing, we can probably get you a better answer ...
source to share