Batch Coding Tutorial I

by Batchcc in Circuits > Microsoft

10144 Views, 18 Favorites, 0 Comments

Batch Coding Tutorial I

3222088_f520.jpg
Batch coding is a very basic programming language that should work on any windows computer ( not apple though ) today I will show you the basics of the programing language.

To Start

maxresdefault.jpg
Open the start menu and type notepad then open notepad and copy the following code into it.


Echo hello
Pause

That's it now save the file but save it as anything.bat the file name must end in .bat for this to work. Now open the file there is a lot of junk but the code should say hello
Now right click on the file and select edit change the code to


@echo off
Cls
Echo hello
Pause


Re open it and there is the word hello
The line "@echo off" will hide any new "junk" (the commands) and "cls" will clear any existing junk.
The two lines can also be combined into one with I will show you in a future tutorial.

Echo

My-First-Batch-File-Program-Print-Hello-World.jpg
Echo would translate to "display the following text"
Echo. Will add a break in the lines ( enter key ) because batch will ignore blank lines
Try experimenting with the echo command for example

@echo off
Cls
Echo hello %username% how are you?
Echo.
Pause

Pause

Fist-Program.jpg
Pause will pause the file
Pause>nul will pause the file and hide the words this file is paused.
Commands can be placed after pause as well like bellow


@echo off
Cls
Echo hello
Pause
Echo how are you?


But here is the problem the file will exit because there are no more commands so for this code have pause at the end.


Goto

The goto command goes to a section of the code


@echo off
Cls
:top
Echo %random% %random% %random% %random% %random% %random%
Goto top

Save this as matrix.bat and open it
Now the goto command can only goto "top" in this code if a ":" sign is in front of the word top with no space like this :top

Set and If

The set command sets environmental variables with can be used if surrounded by percent signs I have used %random% and %username% already now look at the following code


@echo off
Cls
Echo How are you?
Set /p feeling=
Echo your feeling %feeling%
Pause
If %feeling%==good echo that's good
If %feeling%==bad goto bad
:bad
Echo that's bad
Pause

Set /p takes the users input and sets it as a variable in this case feeling and if does something with it now try to Make your own code I will release more tuts later for now view my other batch codes here


https://www.instructables.com/id/Batch-codes/

Thanks