Monday, 25 September 2017

Batch Programming Tutorial

Batch Programming Tutorial


If you have Windows you must know how to write batch programs. Batch programming is the easiest of all the other languages of programming as the programs made by using this programming only works on windows running machines.
Many of you will think that why to learn a programming language that only works in one O.S (Operating System) . I would like to tell you that I learnt this language when I was just 11 years old . I know that you will not belive it but , I did not say it easiest language like that only. So , More than 90% of worlds computers run on windows and that is a big number & if you make a batch programe it will work on almost 90% of the worlds computers.

After All lets Start -

Basics -
To get started you must know the basics of it .

1. ECHO
The most basic command is echo it displays the text you want to display on the screen .
ex. If you command - echo www.hakzcomputer.blogspot.com
Result-


@echo off
This command is necessary for every batch program it omits the repetition of the command in a program

Difference

Without -


With -


2. Pause
It adds a pause to the program and waits for the user to enter anything before it continues


3. Set
This command associate anything to a letter or word
For ex. if you want to set "a" as "echo Hello world"
You can type the Command - "set a= Hello World"
now you can type "%a%" and it will not type "%a%" instead it will type "echo Hello World"
And if you want the command to be written again and again it can be done as you want.


It also can help getting inputs from the user to get a customised output based on user input by the "/p" switch.
For Ex. I want an answer y or n if input y it will echo yes and if input n it will echo no
So I will type programe in a new text file as -

@echo off
:loop
cls
echo Enter Your input -
set /p a=
if %a%== y echo yes && pause && exit
if %a%== n echo NO && pause && exit
msg * Wrong input
goto :loop
:EOF

Output -


In the above program I have first used "@echo off" command to stop the repetition and then I have given the whole program name as :loop and I have cleared the screen by the command "cls" and then I have echoed that "enter your input -" by using echo command then I have used the set command with switch to set "%a%" as the input by the user as you can see above. After that I have used "if" command to check whether %a% (input) is "y" or "n" then if the input (%a%) is "y" it will echo yes and then it will give a pause & exit and vice versa.
If the input is neither "y" nor "n" it will display a message as wrong input by using the command "msg *' then it will go-to :loop , the begining of the program because it has entered wrong input and it will be asked again to enter input and then it will set ........



Pls wait for my next blog post to know more about Batch Programming

Likewise you can check my second blog

 

Wednesday, 6 September 2017

Free money 100% working

Just go to my second blog to earn free money click here to go to my second blog

Sunday, 31 July 2016