You might think "Why did it print instead of "%grapes%"?. Oh yeah, and don't forget the equal sign. That means, if you type in "yes", that would mean that the variable grapes is equal to "yes". Whatever you type in is the data stored in the variable. This whole line creates a (sort of) question, which you need to type something in and press enter to continue. Maybe you can change it to "x" or "y" or something simpler later on, but for now, keep it as grapes. In this case, we are making a "p" variable. Well, the word "set" basically says to the computer "we are creating a variable". You are probably wondering "what the heck?". We understand (sort of) the first three lines. If you type in a response and press enter (or return), it will say "You said: ". If you run this, the cmd box will show up, and will ask you "Do you like grapes?". We are going to create a simple q&a query using variables. In this case, jar a is the "variable", and the jelly beans are the data. Obviously, you are going to go reach for Jar A. A customer comes in and says he wants some of those jelly beans. You have a second jar that contains Chocolate candies, which is labled "Jar B". You have one jar that contains jelly beans, which is labled "Jar A". Here is another real life scenario: You work at the candy store. You guys remember algebra? You still remember what a variable is?īasically, a variable is an object that stores data. I will try to create a video for ya'll to watch that way you can visually see what I am doing. I know this is confusing, but I am doing the best I can to explain this in words. In the case above, the place is named "menu", and the goto statement will take you to "menu". The only difference is what you name the "goto" and "loop" command. The code above, and the one above that will both do the same thing. Just make sure whatever you name it, when you call the "goto" function, you say "goto [whatever you named the :loop". You can name it almost whatever you want. The :loop function does not need to be named "loop". In this case, at the end, the goto function tells the computer to send the user back to the top of the code, where the whole code will repeat itself. In the code, goto is the command that states that you want to go to :loop. In the code, :loop is the place you want to go. Of course you are going to want to aisle C. Imagine you are at a grocery store, looking for some pineapples. I will put this in a real life situation. These two commands go very nice together. Also, try this command, as well as the other commands in the cmd box you opened previously. ", the screen completely clears and echos the next message. You'll notice that each time you click a button it says "Press any key to continue. (Or you can just copy and paste from below if you're lazy I won't mind) offĮcho This is my second batch file program. Take the code from the last step and add 2 "cls" in between your pause and your echo commands, like shown below. It does what many people assume it does: clear the screen. The next three commands we are going to learn are "cls, goto, and :loop" TIP: Make sure you SAVE your work before your run your code, or else your work will not pop up when running the code.Ĭongratulations! You created your first batch file program! Next, we will look at some ways we can use these commands. This is because there was no pause function to freeze the code. Notice if you run the code without the pause, the box will open up and close in an instant. The "pause" command freezes the code, and prints out "Press any key to continue. The "echo" command allows you to print anything you said in the box.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |