So you want to program huh? (Part 1)
July 27, 2008 – 6:27 am
There are many programming languages out there, and perhaps it’s the vast selection of languages that have discouraged any wannabe programmers.
Fret not, if you are not interested in using any utility to start your programming interest, there is always a few options that are already available on your computer without you knowing it.
Yeap OMG, it’s the command prompt window. You are probably already familar with a few commands for it. Today we are taking those commands to it’s full potential, and hopefully proving that programming isn’t a dead subject.
Starting Batch
Now, reach to your notepad. Yes notepad, there is no need for any Visual Studio or any IDEs. We will be using only notepad today.
Now let’s type in some codes shall we?
@echo off echo hello world pause
Save it as hello.bat on your desktop. Now double click the file you just saved.
If you see the above, congratulations! You have just wrote your first Hello World program. If nothing runs, make sure you are pasting the code correctly, make sure you wrote the extention .bat at the back of your filename.
Taking it further
Now that you have made your first program, you are probably not satisfied with what you can do now. No problem, let’s add in some input shall we?
@echo off set /p name=Type in your name : echo Your name is %name% pause
Before we run the code, let me explain what is the code about. You should be wondering what is @echo off , well the purpose of echo off is to make the command prompt as clean as possible. This is due to the nature of the command prompt, as it usually shows the path in front of your commands, such as “C:\>”. Putting echo off, takes away that.
Echo itself is a command that tells the command prompt to show something, and for this program, I am asking the command prompt to show the name variable. A variable is always wrapped up by two percentages sign “%”, this will allow it to be replaced by it’s stored value.
Set is a command that assigns a value into a variable. By writing SET A=Apple , you are asking it to set “Apple” as a value of “A” variable. The /P means you are going to get the input from the user instead of assigning one. By putting SET /P , you are demanding the user to input something, and the prompt will ask the user to input by showing the question you wrote after the “=” sign.
Pause will ask the command prompt to stop processing for awhile, so that the user can see what is displayed.
Now, save the file again, and execute it. You should see the following :
Of course, the name can be anything you typed in.
Now try putting some creative touches to your program, let it input your phone number, address and so on. Try launching it.
Delicious variable
Now of course, you can name your variable anything. %stupidname%, %funnynumber%. But there are a few variables that are determined by the computer, which you can use for different purposes.
Let’s say if you want to know the current date, what do you type?
@echo off echo The current date is %date% pause
The %date% variable is also known as a system variable, where it’s value is already determined by the system. Same goes for time, just use the %time% variable.
Try experimenting on ways you can implement time and date variable in your program! Maybe like a prompt when the user logs in.
Welcome to the system ! Enter Your Name : John Welcome John, the time now is 12:00:02
What’s Next?
All these are suffice for you to begin your programming adventure, in Part 2, we will see how we can use inputs to direct users to different portions of the program. As well as how we can implement looping in the program.










