So basically I have a batch file that requires alot of user input. I was wondering if it was possible to have any filler data already present when the question is asked, and if the user needs to change something, they can go edit that data. For example
And then the user enter their first and last name.
But is it possible to start with a default name that the user can go back and edit if they need?
This probably isn't necessary, But this is the code I use for the user input.
Set /p "Author=Please enter your name: "
And I understand for the Author it wouldn't make much sense to have preset data, but there are other instances where it would be useful for me to do this. Is it possible?
nearly impossible to edit a preset value with pure batch, but you can easily give a default value (works, because
set /p
is not touching the variable, if input is empty)There Is another way yet to achieve this. It uses vbs script to get input and assign it to a variable, -The script can be created within and called from .bat files.
I developed this method as an alternative to accepting user input from set /p in order to validate input and prevent setting of variables with spaces or special characters. *Validation methods omitted as does not relate to the question
Best method is to have the script generator as a secondary .bat file that you can call, as it allows for a lot of versatility regarding the information the vbs input box conveys, as well as being able to be used in any circumstance within one or more .bat files you want to be able to control input defaults with.
In your main program, when Preparing to get input-
REM Define title:
REM Declare variable to be assigned:
REM Define the default Variable Value:
REM getting the Input:
inputscript.bat:
REM exit and cleanup once variable is successfully defined
REM this creates then starts the VBS input box, storing input to a text file.
REM a pause that allows time for the input to be entered and stored is required.
REM opportunity for other validation of input before returning to main.
REM ends the vbs script ready for the next attempt to provide input
REM assigns the input value to the variable name being set in Your Main program.
Take the input to the batch from the indicated file, one line per answer
Another possibility is to use the editv32.exe or edit64.exe program (http://www.westmesatech.com/editv.html), which makes this very simple:
editv32.exe/editv64.exe are unrestricted copyrighted freeware.
Another alternative is ReadLine.exe:
You can get it from http://www.westmesatech.com/misctools.html. Source code is included.
You can set the var first and then prompt the user only if it's not defined like so:
You can also do this backwards where you can define a value if the user didn't define it, like so: