# vbscript-- parameters help!! PLEASE?????



## bforns (Oct 2, 2008)

Can anyone help me create the following script?? I am new to VBScripting and need help. Need this for an assignment, can someone please help??


1. Your script must contains an opening comment that includes your name.
2. The script should have an associated configuration file that will terminate the script after 30 seconds.
3. This little script should display the message “I Require Parameters” if it is started without any command line parameters.
4. If there are parameters, generate the following message:

Greetings, human. I found ? command line parameters.


----------



## shuuhen (Sep 4, 2004)

We don't do homework - see the rules. If you have _specific_ problems/questions related to that program someone might be able to answer them. We also generally like to see the source code, since it's hard to figure out a problem without seeing the source code.


----------



## jamiemac2005 (Jul 5, 2007)

Hey, as shuuhen says we don't give direct h/w etc.

You can find the VBScript User guide(from MSDN) here: 
http://msdn.microsoft.com/en-us/library/sx7b3k7y(VS.85).aspx

The fundementals section would help you through this assignment. If you have code you need help with then post it and we can help =](take a good stab at it first)

Cheers,
Jamey


----------



## bforns (Oct 2, 2008)

This is what i have come up with so far...

> 'Brian Fournier Assignment 1
> Dim WshShl
> Set WshShl = WScript.CreateObject("WScript.Shell")
> WshShl.Popup "I require Parameters"
>
> I don't know how to create a message that allows the user to
> create parameters?
> Can you possibly help?
>
>
> The original assignment again was
>
> 1. Your script must contains an opening comment that includes
> your name.
> 2. The script should have an associated configuration file
> that will
> terminate the script after 30 seconds.
> 3. This little script should display the message “I Require
> Parameters” if it
> is started without any command line parameters.
> 4. If there are parameters, generate the following message:
> Greetings, human. I found ? command line parameters.


----------



## jamiemac2005 (Jul 5, 2007)

Hey, by parameters it means command-line parameters... here's an article on using them in VBScript: http://www.devguru.com/Technologies/wsh/QuickRef/wscript_Arguments.html

I think the idea of your origional assignment is if the count attribute of the Arguments collection(explained in the article above) is 0 then output the first message else output the second...

Cheers,
Jamey


----------



## bforns (Oct 2, 2008)

'Brian Fournier --User command line parameters

Set objArgs = WScript.Arguments
WScript.Echo WScript.Arguments.Count
For Each strArg in objArgs
WScript.Echo strArg
if args.length= 0 then
wscript.echo("I Require Parameters")
else
Wscript.echo("Greetings, human. I found " objArgs " command line parameters.") 
end if 
end if


here is what i have so far and i cannot get the code to execute properly can anyone help.. please??? Thank you... 
This is for the 1st comment listed


----------



## jamiemac2005 (Jul 5, 2007)

Hey, i cleaned up your code =] it now works, run it from a command prompt with arguments and it works fine...


```
'Brian Fournier --User command line parameters

Set objArgs = WScript.Arguments
WScript.Echo objArgs.Count
For Each strArg in objArgs
WScript.Echo strArg
next
if objArgs.length= 0 then
wscript.echo("I Require Parameters")
else
Wscript.echo("Greetings, human. I found " & objArgs.Count & " command line parameters.")
end if
```
Heres an explanation of the problems:
- line 5: the for statement has to be closed with a "Next" statement to make it only do the commands specified within the code bracket.
- line 7: you used args rather than objArgs(simple wrong name)
- line 10: when inserting a variable into a string you have to contagnate it(add it) with "&"s and i'm pretty sure you ment to write objArgs.Count there so i added it...
- the last line had an extra end if statement that didn't need to be there(so it errored)
Other notes:
- you still had Wscript.arguments laying around after having defined objArgs, the script would still work fine as it was but it's better practice to use objArgs after that...

As it is it was a Very good go at the assignment =], you just need to work on your syntax and you'll be fine.... cleaning it was nice and easy(because the logic was perfect behind it)...

Cheers,
Jamey


----------



## bforns (Oct 2, 2008)

Thank you SOO Much!! I can't express how much help you where to me!!!


----------



## jamiemac2005 (Jul 5, 2007)

haha, that's what i'm here for, glad to be of help. You had the logic behind it perfect =]

Cheers,
Jamey


----------

