Dorian
Dorian

Reputation: 417

JScript typed argument in cscript.exe

I'm trying to write a JScript function that accepts variable number of arguments that can be executed by cscript.exe. According to Microsoft documentation here http://msdn.microsoft.com/en-us/library/7yy9shf1(v=vs.90).aspx last function parameter can be an array, but it has to be typed array. Tried this and cscript.exe complained about syntax error near ":".

Then I tried simpler example with just one typed argument:

<job id="Test">
<script language="JScript">
    // Declare a function that takes an int and returns a String.
    function Ordinal(num : int) : String{
       switch(num % 10) {
       case 1: return num + "st";
       case 2: return num + "nd";
       case 3: return num + "rd";
       default: return num + "th";
       }
    }
    // Test the function.
    print(Ordinal(42));
    print(Ordinal(1));
</script>
</job>

I Saved it as "test.wsf" executed with :

cscript.exe //NoLogo test.wsf

Still got the same error. Is cscript.exe not able to use typed arguments (And variable arguments functions)?

Upvotes: 0

Views: 214

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

(Plain) JScript executed by the C/WScript.exe hosts is (very) weakly typed. In particular, it does not support typed arguments (as it's cousin JScript.NET does). See JScript functions.

Upvotes: 2

Related Questions