Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Check Wscript.Argument IS NULL

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60501
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Check Wscript.Argument IS NULL
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Check Wscript.Argument IS NULL - 5/20/2008 9:44:17 PM   
  acidedge2004

 

Posts: 5
Score: 0
Joined: 5/20/2008
Status: offline
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
 
 
Post #: 1
 
 RE: Check Wscript.Argument IS NULL - 5/20/2008 10:26:24 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
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.

(in reply to acidedge2004)
 
 
Post #: 2
 
 RE: Check Wscript.Argument IS NULL - 5/20/2008 10:43:11 PM   
  acidedge2004

 

Posts: 5
Score: 0
Joined: 5/20/2008
Status: offline
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

(in reply to mbouchard)
 
 
Post #: 3
 
 RE: Check Wscript.Argument IS NULL - 5/20/2008 11:38:54 PM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
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

(in reply to acidedge2004)
 
 
Post #: 4
 
 RE: Check Wscript.Argument IS NULL - 5/21/2008 12:27:29 AM   
  acidedge2004

 

Posts: 5
Score: 0
Joined: 5/20/2008
Status: offline
Cheers   ehvbs,

Great help!

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: Check Wscript.Argument IS NULL - 5/22/2008 12:06:04 AM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
Could also do something like


      

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to acidedge2004)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Check Wscript.Argument IS NULL Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts