Hi,

I have a command line script that accepts arguments. The problem I face is I
fell to use the functions IsNull & IsEmpty in order to validate the
arguments. I receive the follwoing error: Microsoft VBScript runtime error:
Subscript out of range.

I do not wish to restrict the user to supply all 4 arguments by using the
Count property but instead I need to know if a specific argument is empty.


Thanks,
Yaniv

Re: WScript.Arguments() by Torgeir

Torgeir
Tue Jul 20 09:58:04 CDT 2004

msnews.microsoft.com wrote:

> Hi,
>
> I have a command line script that accepts arguments. The problem I face is I
> fell to use the functions IsNull & IsEmpty in order to validate the
> arguments. I receive the follwoing error: Microsoft VBScript runtime error:
> Subscript out of range.
>
> I do not wish to restrict the user to supply all 4 arguments by using the
> Count property but instead I need to know if a specific argument is empty.
Hi

This is one way of doing it:


Set arrArgs = WScript.Arguments

On Error Resume Next
strArg0 = "" ' default value if argument not given
strArg0 = arrArgs(0)
strArg1 = "" ' default value if argument not given
strArg1 = arrArgs(1)
strArg2 = "" ' default value if argument not given
strArg2 = arrArgs(2)
strArg3 = "" ' default value if argument not given
strArg3 = arrArgs(3)
On Error Goto 0




--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: WScript.Arguments() by msnews

msnews
Tue Jul 20 10:16:19 CDT 2004

Thanks for your reply,


strArg1 = "LOCALHOST" ' default value if argument not given
WScript.Echo strArg1 ' will echo LOCALHOST
strArg1 = arrArgs(1) ' when get to this line i recive the same error, still
how do i check the user input to know if a value was supplied?





----------------------------------------------
"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:ueHO5ombEHA.3480@TK2MSFTNGP11.phx.gbl...
> msnews.microsoft.com wrote:
>
> > Hi,
> >
> > I have a command line script that accepts arguments. The problem I face
is I
> > fell to use the functions IsNull & IsEmpty in order to validate the
> > arguments. I receive the follwoing error: Microsoft VBScript runtime
error:
> > Subscript out of range.
> >
> > I do not wish to restrict the user to supply all 4 arguments by using
the
> > Count property but instead I need to know if a specific argument is
empty.
> Hi
>
> This is one way of doing it:
>
>
> Set arrArgs = WScript.Arguments
>
> On Error Resume Next
> strArg0 = "" ' default value if argument not given
> strArg0 = arrArgs(0)
> strArg1 = "" ' default value if argument not given
> strArg1 = arrArgs(1)
> strArg2 = "" ' default value if argument not given
> strArg2 = arrArgs(2)
> strArg3 = "" ' default value if argument not given
> strArg3 = arrArgs(3)
> On Error Goto 0
>
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx



Re: WScript.Arguments() by Torgeir

Torgeir
Tue Jul 20 10:27:25 CDT 2004

msnews.microsoft.com wrote:

> Thanks for your reply,
>
>
> strArg1 = "LOCALHOST" ' default value if argument not given
> WScript.Echo strArg1 ' will echo LOCALHOST
> strArg1 = arrArgs(1) ' when get to this line i recive the same error, still
> how do i check the user input to know if a value was supplied?
Hi

You need to use "On Error Resume Next". When the argument assigning
is finished, you should cancel it with "On Error Goto 0" (see my
first post).

Try this (note that the first argument is arrArgs(0) and not
arrArgs(1)):


Set arrArgs = WScript.Arguments

On Error Resume Next
strArg1 = "LOCALHOST" ' default value if argument not given
' will echo LOCALHOST
WScript.Echo strArg1
strArg1 = arrArgs(1)
' will echo LOCALHOST if arrArgs(1) doesn't exist, else it
' will echo the content of arrArgs(1)
WScript.Echo strArg1



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: WScript.Arguments() by msnews

msnews
Tue Jul 20 10:43:42 CDT 2004

got it,

Many thanks again I appreciate your response.


Regds,
Yaniv


--------------------------
"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:ujD7S5mbEHA.3944@tk2msftngp13.phx.gbl...
> msnews.microsoft.com wrote:
>
> > Thanks for your reply,
> >
> >
> > strArg1 = "LOCALHOST" ' default value if argument not given
> > WScript.Echo strArg1 ' will echo LOCALHOST
> > strArg1 = arrArgs(1) ' when get to this line i recive the same error,
still
> > how do i check the user input to know if a value was supplied?
> Hi
>
> You need to use "On Error Resume Next". When the argument assigning
> is finished, you should cancel it with "On Error Goto 0" (see my
> first post).
>
> Try this (note that the first argument is arrArgs(0) and not
> arrArgs(1)):
>
>
> Set arrArgs = WScript.Arguments
>
> On Error Resume Next
> strArg1 = "LOCALHOST" ' default value if argument not given
> ' will echo LOCALHOST
> WScript.Echo strArg1
> strArg1 = arrArgs(1)
> ' will echo LOCALHOST if arrArgs(1) doesn't exist, else it
> ' will echo the content of arrArgs(1)
> WScript.Echo strArg1
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx