In the previous tutorial we learned the core essentials of writing batch files.

If you have no clue what batch is, but want to learn it, refer to the "Very Basic Batch Tutorial".

In this tutorial you will learn more advanced commands and how to use them to create an application.

Step 1: Variables Step (1/3)

Variables are things that are subject change.
When we create a variable, we are creating something that we want the computer to remember for us, something that we can use later on in a program;
we give the computer the value that we want to store and we give it a label to store it under.

we can create integers and strings using variables.

To create a variable you need to learn the SET command.

The SET command is what creates variables;

SET name=value

Type the following into your CMD:
SET name=hello

'name' is the name of the variable, and 'hello' is what the variable is storing

so now every time you type "echo name" it should say "hello" yes?

if you want to display a variable you must put percentage (%) signs around it.

So therefore if you type "echo %test%" and it should say "hello" yes?
<p>To display Multiplication Table of 3:</p><p>===========================================</p><p>@echo off</p><p>set a=1</p><p>set b=3</p><p>set n=11</p><p> :lb</p><p>if %a%==%n% goto end</p><p>set /a c = %b% *%a% </p><p>echo %b% x %a% = %c% </p><p>set /a a = %a%+1</p><p>goto lb</p><p>:end</p><p>pause</p><p>===============================================</p><p>output:</p><p> 3 x 1 = 3</p><p> 3 x 2 = 6</p><p> 3 x 3 = 9</p><p> 3 x 4 = 12</p><p> 3 x 5 = 15</p><p> 3 x 6 = 18</p><p> 3 x 7 = 21</p><p> 3 x 8 = 24</p><p> 3 x 9 = 27</p><p> 3 x 10 = 30</p><p>Press any key to continue . . .</p>
<p>hola ........ que puedo hacer o qu&eacute; c&oacute;digo a utilizar para un extracto de la informaci&oacute;n por lotes desde un servidor de base de datos SQL 2008 --- --- POR FAVOR AYUDA GRACIAS</p>
<p>hola........ como puedo hacer o que c&oacute;digo usar para que un batch extraiga informaci&oacute;n de una base de datos de SQL SERVER 2008 --- PORFAVOR AYUDENME --- GRACIAS</p>
<p>This Instructable inspired me to make one like it myself.<br>If you want to check it out....<br>http://www.instructables.com/id/Basic-Batch-command-list/</p>
I have a question I want it to do a goto comand when you type in 1 how do you do that<br/>so far I hav<br/>@echo off<br/>echo welcome to brian<br/>echo brian will now add 4 1698 times<br/>set/a num=4<br/>:furt<br/>set/a num=%num%+4<br/>echo %num%<br/>if %num%==6792 goto :end<br/>goto :furt<br/>:end<br/>echo you have reached 6792<br/>echo continue?<br/>set v1=goto :count1<br/>set v2=goto :g <br/>echo press 1 to continue<br/>echo press 2 to stop<br/>set/a nu=6792<br/>set/a n=0<br/>set /p you=<br/>if %you%==1 echo %v1% <br/>if %you%==2 echo %v2%<br/>
<p>@echo off</p><p>color 0a</p><p>title Brian the math batch program</p><p>echo Welcome to Brian</p><p>echo Brian will now add 4 1698 times</p><p>pause<br>set num=4</p><p><br>:furt<br>set /a num=%num% + 4<br>echo %num%<br>if %num%==6792 goto end</p><p>goto :furt<br></p><p>:end</p><p>color 0b</p><p>set v1=count1<br>set v2=g</p><p>set /a nu=6792<br>set /a n=0</p><p>cls</p><p>echo You have reached 6792<br>echo Continue?</p><p>echo.<br>echo Press 1 to continue<br>echo Press 2 to stop</p><p>set /p you=:<br>if %you%==1 goto %v1% <br>if %you%==2 goto %v2%</p>
<p>Well if you want it to go to a tag such as :main just do </p><p>set /p number =</p><p>if %number% == 1 goto main</p>
I fixed your code. <br> <br>@echo off <br>echo welcome to brian <br>echo brian will now add 4 1698 times <br>set /a num=4 <br>:furt <br>set /a num=%num%+4 <br>echo %num% <br>if %num%==g792 goto end <br>goto furt <br>:end <br>echo You have reached 6792 <br>echo continue? <br>echo press 1 to countinue <br>echo press 2 to stop <br>set /a nu=6792 <br>set /a n=0 <br>set /p you= <br>if %you%==1 goto count1 <br>if %you%==2 goto g <br> <br>
is this the whole program? if so, then i don't understand where %v1% and %v2% are meant to goto. but if u want it to work, take out the &quot;echo&quot; statements in the last two lines:<br/><hr/>if %you%==1 %v1%<br/>if %you%==2 %v2%<br/><hr/>
Hey man, I have a small problem. I'm tryign to make a .bat to begin a thing based of the %random% command. I'd put say.... 3485804 and if it goes to it, it begin a "Insert thing evil program here". I presumed this would work @echo off title Random Number Gen by seJma color 2f :top cls echo Your Number is... echo %random% if %1227% goto begin goto top :begin pause start www.1227.com
Nevermind<br/>i used the if %random%==1227 goto begin<br/>
How do i limit the number? Is the a "equal to or less than" or just "less than"?
<p>set /a a=%random% %%!(limit of numbers that can be chosen) +1<br>example: set /a a=%random% %%!10 +1<br>it sets &quot;a&quot; to equal a random number between 0 and 10</p>
Even though it's old... <br> <br>SET /a Var=%RANDOM% %%max + min <br> <br>That method uses modulo expressions to constrain the number. <br> <br>Example: <br>If &quot;max&quot; had the value of 10, and &quot;min&quot; had the value of 1... <br>The variable &quot;Var&quot; would be a number between 1 and 10.
<p>Amazing! :D Really funny and helpful tutorial!</p>
<p>What does /a mean?</p>
<p>Can you please explain to me what /p means??</p>
<p>hey admin,</p><p>I need to prepare a batch file to set <strong><em>Security policy</em></strong> in <strong>local policy</strong> of my systems</p><p>Can you help in this regards</p><p>Regards,</p><p>Amit</p>
<p>Nice tutorials. I completed both of two for beginers.</p>
<p>this was really awesome, I got to learn a lot from both of your tutorials, this one &amp; that of the basic one :)</p>
im very new to batch and i want to know everything. how do u open up .bat files on notepad and how do u create an account and the number thing wont work for me. plz help
&nbsp;You can't open them in Notepad without &quot;hacking&quot; your registry, a much simpler idea is to install Notepad++ (Google it, don't feel like putting a link) and it's better cause Notepad++ has syntax highlighting.
It's called Right-click, EDIT.
Your random number generator is great, though one problem. It increments in 10s instead of generating random numbers. Do you think you can fix this? Otherwise, a really excellent Instructable.
if you think about it, a random number generator is virtually impossible. it will have to follow some sort of pattern or otherwise create something that changes the pattern itself and even THAT is considered a pattern....
Okay, I just learned how to use this for the most part, but I just have one question... How do you get a batch file to open and run on your computer???
&nbsp;Double-click.........<br /> <br /> Is this your first computer?<br />
I&nbsp;don't remember making that comment, haha. Whoops.<br />
You fell asleep while your laptop was open, probably. My dad chatted on Skype while asleep one time. and it was not gibberish it was like, when he said he was just woke up on the 4th message, I was like, &quot;He was asleep?&quot;. And I have sleep talked before.
can i do the same thing so it will count letters and numbers such as for running through various combinations of words/ digits?
I pressed 2, and it said "BYE!!!" instead of "BI!" What a rip-off.
lol thats not a rip-off lol.
haha, very observant......i'll change it just now
This is a bit wird but variables r easy
Agh, my brain. splat.
Nah, more like plop. Unless you watch a lot of TV. Then it's ker-plunk (slurp). Sorry, been watching too many hulu commercials.
Ha! Like your icon (It`s not an avatar rofl)
Excuse me admin, This is a part 3 of 3, i don't think it needs much more but if you insist. -Just thinking, Chris
Love it, nice man. Also using the &quot;if %you%==1&quot; command, made a game for my friends that if you get a question wrong you go to www.1227.com and if not, you continue...<br/><br/> -Cheers, Chris<br/><br/>
what is 1227.com
Its a rickashtely community that has every rick rolol link imaginable, and you CAN view them too, its not advised
Send them to tubgirl.com
Which is?????
Go there, it has this really funny picture on the front page.
Sorry, but NeoDudeMan beat you to this instructable! He has already made a basic, intermediate, and advanced instructables! Your is almost the same... I wonder if there is any copy'n'pasting involved...
yeah his tutorials are pretty good, but i'm not a "copy, paste" type of guy, I just wanted to explain batch through my eyes.
So you have already met Sejma, then? you acted as if he was new to you! P.S. Show us how you made the flash drive backup, please.

About This Instructable