loading
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?
NO

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?
YES
<p>IT HELPED ME A LOT THANKS FOR YOUR KNOWLEDGE</p>
<p>I used this tutorial and comments below to make a program to tell my GF how much I love her. Check it out :D</p><p>@echo off</p><p>color 1A</p><p>cls</p><p>echo I love you this much...</p><p>pause</p><p>set /a v=1</p><p>:top</p><p>set /a v=%v%+1</p><p>echo I love you this much %v%</p><p>if %v%==5000 goto one</p><p>if %v%==10000 goto two</p><p>if %v%==15000 goto three</p><p>if %v%==15010 goto four</p><p>if %v%==20000 goto five</p><p>if %v%==20010 goto six</p><p>if %v%==20020 goto seven</p><p>if %v%==20200 goto eight</p><p>if %v%==20300 goto nine</p><p>if %v%==20320 goto ten</p><p>goto top</p><p>:one</p><p>echo Wow that is a lot of love! Would you like to continue?</p><p>pause</p><p>goto top</p><p>:two</p><p>echo OMG that is a lot of love! Are you sure you want to continue?</p><p>pause</p><p>goto top</p><p>:three</p><p>echo Well, this is just a huge amount of love right here!</p><p>echo One wonders if there can be any more love in the world.</p><p>echo Are you sure you want to continue?</p><p>pause</p><p>goto top</p><p>:four</p><p>echo Seriously tho, are you sure you want this to go on?</p><p>echo There really is an infinite amount of love here...</p><p>pause</p><p>goto top</p><p>:five</p><p>echo Dude, that really is a lot of love isn't it!</p><p>echo Surely this is enough love for one person.</p><p>echo I suggest you quit now and do not continue</p><p>pause</p><p>goto top</p><p>:six</p><p>echo Fine, don't listen to me then.</p><p>pause</p><p>goto top</p><p>:seven</p><p>echo Aww, who am I kidding? Your independence just makes me love you more.</p><p>echo Want to see how much?</p><p>pause</p><p>goto top</p><p>:eight</p><p>echo Woah, I'm getting a bit too excited now.</p><p>echo Just give me a second to catch my breath.</p><p>pause</p><p>goto top</p><p>:nine</p><p>echo Hey, what do you think I am? A machine?</p><p>echo Just give me a minute and I will keep on loving you all night.</p><p>pause</p><p>goto top</p><p>:ten</p><p>echo zzzzzzzzzzzzzzzzzzzzzzzzzzzz</p><p>pause</p><p>echo zzzzzzzzzzzzzzzzzzzzzzzzzzzz</p><p>pause</p><p>echo zzzzzzzzzzzzz(yawn)... What?</p><p>echo No, I wasn't asleep baby. I was just resting my eyes.</p><p>pause</p><p>:eleven</p><p>set /a v=%v%-1</p><p>echo zzzzzzzzzzzzzzzzzzzzzzzzzzzz %v%</p><p>if %v%==0 goto twelve</p><p>goto eleven</p><p>:twelve</p><p>echo (Yawn) Good morning baby. Guess how much I love you...</p><p>Pause</p><p>Goto top</p>
<p>For useful Batch files visit</p><p><a href="http://batch798.blogspot.in/" rel="nofollow">http://batch798.blogspot.in/</a></p>
<p>Is it possible that I use things that someone typed/filled in in the cmd? For example,</p><p>You let someone type his or her name on the cmd and somehow you can bring that up again with num= or anything else?</p>
<p>I made a program to add, subtract, divide or multiply according to the user's wish. Check this out. If you have some suggestions, please tell</p>
<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>confusing</p>
<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