After experiencing a lot of down time, We decided to move this site to
CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.
Check Wscript.Argument IS NULL
Author |
Message
|
acidedge2004
-
Total Posts
:
5
- Scores: 0
-
Reward points
:
0
- Joined: 5/20/2008
-
Status: offline
|
Check Wscript.Argument IS NULL
Tuesday, May 20, 2008 10:44 PM
( permalink)
hey, I have a script that I want to use a conditional on to determine how to execute it. I want to have WScript.Arguments(1) IsNull int he script to check whether a 2nd argument was passed to the script from the command prompt. I have tried several variations and keeping getting syntax error messages or "Object is required" I have tried IsEmpty(), IsNull(), Wscript.Argument(1) Is Null. I have passed the contents of wscript to x then used the functions on x and checked if it = '' but keep getting problems. SOmetimes the condition is ignored and the script executed anyway. Does anyone know how to check if an argument is null or empty? Cheers, Mike
|
|
|
mbouchard
-
Total Posts
:
2110
- Scores: 27
-
Reward points
:
0
- Joined: 5/15/2003
- Location: USA
-
Status: offline
|
RE: Check Wscript.Argument IS NULL
Tuesday, May 20, 2008 11:26 PM
( permalink)
Have you tried count? To see if the proper number of arguements have been passed? Also, post your code, may help get help.
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|
|
acidedge2004
-
Total Posts
:
5
- Scores: 0
-
Reward points
:
0
- Joined: 5/20/2008
-
Status: offline
|
RE: Check Wscript.Argument IS NULL
Tuesday, May 20, 2008 11:43 PM
( permalink)
I did not post the code as I do not really think it is specific to my code. I want to know if it could be done in general, so I could use it in this code and future scripts. Even basic code like: If IsNull(WScript.Arguments(1)) Then WScript.Echo "Hello" Else WScript.Echo "Goodbye" End If I hope you can see what I mean by this. I tried IsEmpty in place of IsNull and ='' but got nothing. I have googled this and found nothing to help me either. I haven't tried count, never even thought of that! Though it may work in this instance, I would stil like to know if anyone knows a method similar to the one I have shown above. Cheers, Mike
|
|
|
ehvbs
-
Total Posts
:
3190
- Scores: 108
-
Reward points
:
0
- Joined: 6/22/2005
- Location: Germany
-
Status: offline
|
RE: Check Wscript.Argument IS NULL
Wednesday, May 21, 2008 12:38 AM
( permalink)
Hi acidedge2004, WScript.Arguments is an array (for all practical purposes), that contains the space delimited arguments from the command line. If there are no parameters, the array will be empty: WScript.Arguments.Count == WScript.Arguments.Length == 0 Given one argument WScript.Arguments.Count == WScript.Arguments.Length == 1 you can access it by WScript.Arguments( 0 ) - remember VBScript arrays are zero-based. Of course it can't be 0, null, or empty, because then it couldn't be in the array. In general: passing n arguments/options will result in an array of Count/Length == n with n non empty strings (Len(WScript.Arguments( i ) > 0) accessible via index 0 ... (n-1). Regards ehvbs
|
|
|
acidedge2004
-
Total Posts
:
5
- Scores: 0
-
Reward points
:
0
- Joined: 5/20/2008
-
Status: offline
|
RE: Check Wscript.Argument IS NULL
Wednesday, May 21, 2008 1:27 AM
( permalink)
Cheers ehvbs, Great help!
|
|
|
4scriptmoni
-
Total Posts
:
224
- Scores: 0
-
Reward points
:
0
- Joined: 5/3/2007
-
Status: offline
|
RE: Check Wscript.Argument IS NULL
Thursday, May 22, 2008 1:06 AM
( permalink)
Could also do something like
set objArgs = WScript.Arguments
if WScript.Arguments.Count = 3 then
wscript.echo "Total number of arguments: " & WScript.Arguments.Count
strEmailTo = WScript.Arguments(0)
strSub = WScript.Arguments(1)
strBody = WScript.Arguments(2)
for each strArg in objArgs
wscript.echo strArg
next
else
wscript.echo"Error, Must pass arumgnets sendemail <email to> <subject> <body>"
wscript.quit
end if
|
|
|
Online Bookmarks Sharing: