![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | 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. > 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 Specs![]() |
| | #4 (permalink) |
| | 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? lately? I'd just like to know. They have little in common - saying this without really knowing VBscript. Armin |
My System Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 > 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 Specs![]() |
![]() |
| 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 | |||