For those who are wondering how to make some sort of DOS(command prompt) program that continues to allow the user to make commands until they want to quit. We can create a menu driven DOS program. At the end of this tutorial i have a an example of what one can look like.
First lets go to the environment you will make such a program in. Such an environment is simply any text editor. So open up a text editor. Notepad will suffice if you have it. This is where you will type your commands.
The "CLS" command. This command clears the screen of writing. Very important if you want to clear up and make your program more readable or look neater.
The "ECHO" command. This command will allow you to write to the screen. As an example(Ex).
ECHO Hello World. Will print Hello World to the screen.
A helpful tip is ECHO. <---period after echo just prints a newline.
The "GOTO" command. This command is most important in this example of the menu driven program. This command is also good if you don't want your program to close as soon as it runs like a DOS program would.
The GOTO can be used to as it says GOTO a certain tag in the program. A tag being lets say :start, and :end.
To create a tag in your program just put a ":" before the name of the tag.
ECHO Hello World
This program will go into an infinite loop. For the program will read the line :start, the print Hello World, then GOTO the tag start,from here it will print Hello World, then GOTO the start tag again. You get the idea.
Problem for you. How you would you have this program skip the lines ECHO Hello World, and GOTO start?
If you said put GOTO end, before the echo statement. You are correct!
The "IF" command. This command will allow you to execute statements/commands depending on if a certain condition you set in your IF command is true. We will touch on this after i show you the set command.
The "SET" command. This command will allow you to SET a variable to equal something. For our case we want to use it to create a variable and allow the user to enter a value at choice. For this we use the " /p" statement with SET. As an example
SET /p M=
The above example will wait until the user enters a value for the newly created variable M.
Variables are created and used as data to hold and store values.
You can also have info for your user after the SET command.
SET /p M=Enter a value for some variable M then press Enter:
Now back to the IF command. An example of this command can be seen in the below example.
IF %M% == 69 GOTO :start
This example shows the use of how to access a variable and how to write a condition. The condition in the example is shown by %M% == 69. Lets explain whats going on here. The %M% code is how we access the variable M and use it in our condition. The == code is to see if there is an equivalence to the variable M and the number 69. So as the example is stating. IF the variable M is equal to 69 THEN GOTO :start.
These commands are all you will need to use to make a menu driven DOS program.
Before i show my final DOS program for this blog. I will now explain the use of two more commands.
The "START" command. This command is used to well START a file. Now in order to do this we need to be in the same working directory as the file(this is a little more complicated for this tutorial).
Ex. START Minecraft.exe
The "CD" command. This command stands for change directory. Lets say your working directory is
C:\user\somename\, and you want to move to just the D drive. Then you would type:
Now after learning about all these commands and writing crazy code into a text file . How to we get this program to run. Because honestly DisposedCheese i think your crazy because when i click on the program it just opens the text editor again to edit.
Well now what we do is we want to change the extension of our text file to a .bat. This convert the text file into a batch file. A batch file will run using command prompt and execute your lines of code accordingly from top to bottom.
As a result the final menu driven DOS program. Feel free to copy and change things accordingly to make your own. You might want to take the START and CD command out. Also you may want to read the code and see if you can make sense of what is going on. As well as what happens when you enter certain values at the prompts.
Ex Menu Driven DOS Program
ECHO DisposedCheese's Menu
ECHO Entering 0 continues.
ECHO Entering 1 quits.
ECHO Entering 2 starts minecraft.
SET /P M=Type 0, 1 or 2, and enter:
IF %M%==0 GOTO ZERO
IF %M%==1 GOTO ONE
IF %m%==2 GOTO TWO
IF %M%==9 GOTO END
ECHO i am glad you wanted to continue.
ECHO Why you want to end the batch, too bad.
ECHO if you want to quit type 9 at the prompt.
CD C:\some directory\desktop
I hope you enjoy this.