It is interesting how everything appear to us in the screen simpler than what it really is. Look now at the header of my blog, this has a long code. Look at the title of the blog, it has a code to be appeared this way. Everything on the computer, windows, and internet is edited by Computer Language, written as codes, tested and then appear to us in this way. We can use it easily by just clicking the link. I am sure almost anyone who use the computer knows this. But I like to share what I am learning now; how to program. It is not a very hard thing once you understand it; it is just like a chain. Things are linked and connected to each others...if you didn't understand the first step then you should not move on. I did not program anything yet, I am still learning and sharing my readings with you.
I first started reading about Visual Basic Programming Language, because this language uses symantics that somehow more readable language than other programming languages which make it easier to grab and apply. So obviously, I will understand everything from the roots in a fun, easy way. You can download it from here to your computer so you can start programming. It's free! let's get started.
Open a new project to start with, but before that you need to make sure that the button "Start without Debugging" is one of the options of "Debug" in the tool bar.
This is a screenshot of the bar itself:
" Debug" is the process that trace the bugs (errors) and fix them so you use the debugger to fix them or find where they are. For example, if you have a minor mistake in the code, this debugger will fix it and tell you why the program didn't run as you expected. If you " Start Without Debugging " then the compiler will start the program without enabling the debugger to trace the errors. The next step is creating the simple program which beginner programmers always call it "Hello World!"... I found it funny, because it is really a new world (programming) to say "Hi" to.
As you insert the "Hello , world!" code between the Sub Main , you can run the program by clicking " Start Without Debugging" in the tool bar. It is the button we added previously. And as you can see, whenever a code end or starts there should be an End Sub or Sub Main (starting the code). The "Sub" is actually a “subroutine" which what do the actual work in the program, everything in between is part of the subroutine.
Are you wondering what contains the subroutine? Well, there are two statements, they called "Module" or "Class"…and what they do is having all the information and codes under them. And of course, there is "End Module" that ends the code. Yes, I told you everything is like a chain; everything is part of something and contains different information.
Now, you need to define the variable ( where it stores the data on the computer's memory like text, numbers, integer..etc) and specify the type of it. For example, I want to store this text value " Hello, world!". So what I do is define this variable and name it whatever I like, I would name it " World " or " Message " or any subject you want; in order to save this text in the variable, I will define it as String so I can store them on the computer. " String " is a type to define a variable, and there are many other types we will learn later on.
"Console.WriteLine" is a function in this VB Program that print the codes on the screen while running the program. So when you write Console.WriteLine(" Hello, world!") it will print " Hello , world! "on the screen. It basically print the value of the variable.
Those are the types of Variables:
1) Integer - values between -2,147,483,648 and 2,147,483,647.
2) Byte - values from 0 to 225.
3) Decimal - values with decimal places between ±1.0×10-28 and ±7.9×1028.
4) String - sequence of character.
5) Char - value of one character.
6) Boolean - logical value, True or False.
Let me give another example of different variable type.
I want to calculate the sum of 1 and 3 . Logically, they are integer, so I will use variable of type Integer. So I will write " Dim Total as Integer " - this tells the computer to define the variable as Integer type. Then I would use it as " Total = 4 ". The computer will finally calculate it and save the results as a Total variable.
And by the way, you can't use as a "Integer" value when you put quotes ("") around your variable. VB Program will receive it as a "String".
Now as you put the codes in the right places and define the variables correctly, this what you should see before running the program:
Press any key to dismiss the window.
That was our first lesson..I hope I will get to more complex programs after a while. My next lesson will be about how to use mixed Variables and deal with errors in your program.