Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How to read a user input value from command line and store it in a variable?

Reply
 
Old 03-25-2009   #1 (permalink)
Tony Bansten


 
 

How to read a user input value from command line and store it in a variable?

I would like to read a user input from command line and store it in a variable aaa.

In good ol' DOS batch scripts there is a command:

set /p aaa="Please enter value: "

How do I do this in VBscript?

Is there a way to define a default value? In other words if the user simply hits RETURN
the value in variable aaa should not be empty but contain instead e.g. "unknown" or 0 (=zero)

How do I define such a default value in VBscript?

Again: the input should not be entered in a GUI based entry field but at the command prompt.

Tony


My System SpecsSystem Spec
Old 03-25-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: How to read a user input value from command line and store it in a variable?


"Tony Bansten" <tonytony@xxxxxx> wrote in message
news:49c9f0be$0$31862$9b4e6d93@xxxxxx-online.net...
Quote:

>I would like to read a user input from command line and store it in a
>variable aaa.
>
> In good ol' DOS batch scripts there is a command:
>
> set /p aaa="Please enter value: "
>
> How do I do this in VBscript?
>
> Is there a way to define a default value? In other words if the user
> simply hits RETURN
> the value in variable aaa should not be empty but contain instead e.g.
> "unknown" or 0 (=zero)
>
> How do I define such a default value in VBscript?
>
> Again: the input should not be entered in a GUI based entry field but at
> the command prompt.
>
> Tony
Strange . . . for a long time people have been complaining about the
unfriendly black-screen user input method offered by set /p, and now you
wish to use precisely this unfriendly technique . . . AFAIK, VB Script has
no such facility. Its input tool is, as you probably know, the InputBox
method.

A rather clumsy way to meet your requirement would be to use a batch file
that does two things:
- It uses set /p to prompt the user for an input.
- It writes the response to a text file.

Your VB Script will also do two things:
- If invokes the batch file like so:
oWshShell.Run "d:\temp\test.bat", 3, True
- It reads the input from the text file.

I think the InputBox method would be a lot more elegant.


My System SpecsSystem Spec
Old 03-25-2009   #3 (permalink)
Clive Lumb


 
 

Re: How to read a user input value from command line and store it in a variable?


"Tony Bansten" <tonytony@xxxxxx> a écrit dans le message de news:
49c9f0be$0$31862$9b4e6d93@xxxxxx-online.net...
Quote:

>I would like to read a user input from command line and store it in a
>variable aaa.
>
> In good ol' DOS batch scripts there is a command:
>
> set /p aaa="Please enter value: "
>
> How do I do this in VBscript?
>
> Is there a way to define a default value? In other words if the user
> simply hits RETURN
> the value in variable aaa should not be empty but contain instead e.g.
> "unknown" or 0 (=zero)
>
> How do I define such a default value in VBscript?
>
> Again: the input should not be entered in a GUI based entry field but at
> the command prompt.
>
I hope that we are not doing your homework for you

Run this with the cscript shell

Dim StdIn, StdOut
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
StdOut.WriteLine "Please enter value"
str = StdIn.ReadLine
if len(str)=0 then str="0"


My System SpecsSystem Spec
Old 03-25-2009   #4 (permalink)
Armin Zingler


 
 

Re: How to read a user input value from command line and store it in a variable?

"Tony Bansten" <tonytony@xxxxxx> schrieb
Quote:

>
> How do I do this in VBscript?
Is there a reason why VBscript questions are also sent to the VB.Net group
lately? I'd just like to know. They have little in common - saying this
without really knowing VBscript.


Armin

My System SpecsSystem Spec
Old 03-25-2009   #5 (permalink)
Mr. Taco


 
 

Re: How to read a user input value from command line and store itin a variable?

Check out the console application at this link:
http://msdn.microsoft.com/en-us/bb964686.aspx

It's under the "Application Samples" folder.

It's a good example of how to read and write to the console.

-Taco

Tony Bansten wrote:
Quote:

> I would like to read a user input from command line and store it in a variable aaa.
>
> In good ol' DOS batch scripts there is a command:
>
> set /p aaa="Please enter value: "
>
> How do I do this in VBscript?
>
> Is there a way to define a default value? In other words if the user simply hits RETURN
> the value in variable aaa should not be empty but contain instead e.g. "unknown" or 0 (=zero)
>
> How do I define such a default value in VBscript?
>
> Again: the input should not be entered in a GUI based entry field but at the command prompt.
>
> Tony
>
My System SpecsSystem Spec
Old 03-25-2009   #6 (permalink)
Clive Lumb


 
 

Re: How to read a user input value from command line and store it in a variable?


"Tony Bansten" <tonytony@xxxxxx> a écrit dans le message de news:
49c9f0be$0$31862$9b4e6d93@xxxxxx-online.net...
Quote:

>I would like to read a user input from command line and store it in a
>variable aaa.
>
> In good ol' DOS batch scripts there is a command:
>
> set /p aaa="Please enter value: "
>
> How do I do this in VBscript?
>
> Is there a way to define a default value? In other words if the user
> simply hits RETURN
> the value in variable aaa should not be empty but contain instead e.g.
> "unknown" or 0 (=zero)
>
> How do I define such a default value in VBscript?
>
> Again: the input should not be entered in a GUI based entry field but at
> the command prompt.
>
> Tony
>
I hope that we are not doing your homework for you

Run this with the cscript shell

Dim StdIn, StdOut
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
StdOut.WriteLine "Please enter value"
str = StdIn.ReadLine
if len(str)=0 then str="0"


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: How to display a variable value in a dialog box and how to read user input? VB Script
How take an user input in command line Options PowerShell
Read-Host issue, won't store to variable when using multiple read-host lines PowerShell
Execute from command line with environment variable in path PowerShell
Command Line Input? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46