Sunday, October 6, 2013

TUTORIAL 2: USE VARIABLE

Do you have any idea what variable is? little2more will try to help you to know what is variable in basic programming.
I will try not to use complex words to explain this.

WHAT IS VARIABLE IN TERM OF PROGRAMMING?

Imagine variable as a pail. Put in a red ball into this pail.
Then, you have another a green ball and put it in into another pail.

Variable is like a pail

Variable is a storage in your computer's memory. It is like a pail, you can put an object into it. Objects can be different types, sizes or colors.
How about if you got a lot of pails and different type of objects?
I'm sure you want to name them or put a label to arrange them neatly. Later on if you want to put all the pails in one store room, you will appreciate for what you have done.

Put in label to pails
Here same goes to variable. Declare and initialize those variables we want to use in the program.

The tutorial 2 shows how to use variable in your program.
STEP 1:Comment your first lesson. You will not get a proper output if not comment those lines of code.
You need to highlight the codes and go to toolbar with the multiple line symbol then click the button.
Step 2: Write next code. Remember to use meaningful comment. Clear and meaningful comment are the good practice in programming.
Many programmers don't do this but if you are some kind of organize person or like to make other people happy with your job, you will do this.

Here is the output(below) after click run button

User not able to input any value because of the program above is unfinished. It was like you are writing a book but hang with the story. So let's get finish it.

STEP 3: Let's continue the coding. Write the codes below:
fName = Console.ReadLine()
Console.WriteLine("Your Name is " & fName)

Click run button and get the output below.

After click run button, the first output appears. We need to key in value to continue the program.
Second output shown after user key in the value

What are we actually doing?
Commented out the selected lines in vb.net.
In vb.net symbol ' is use for comment the line of codes.
We also comment to put description of the code.
Meaningful and clear but simple description of your lines of code are appreciated by everyone who read your program.
Let's make everyone happy to read your codes even you will be happy.
How many programmer hate to read their own code especially their old programs.
Commenting your code with clear and simple explanation at least make you less headache or yawn too much.

Tutorial 2 above do this action:-
Comment the unused code.
When we comment the line of codes, the compiler of Visual Basic will ignore the text following it.
You may want to use the line of codes back someday, that is why we do not erase the code permanently.
When the time comes, uncomment back the line of codes for whatever of your objective.
We also use comment to put a simple explanation of the code

How to comment lines of code?
Firstly highlight the codes you want to commented out.
Then Click comment out the selected lines button at the toolbar


Below is a result after comment the codes using comment button. If necessary use uncomment button.


Declare a variable called fname.
The tutorial 2 above shows how to declare (or put a name) variable fname.
Second line of code is for your program interact with user.
Prompt out some text such as "What is your name?"
Third line of code is the program take the answer from the user(input from user).
The answer from user(think a red ball)then you put into a variable called fname (pail labelled red ball).

No comments:

Post a Comment