twitter
    Find out what I'm doing, Follow Me :)
Showing posts with label visual basic.net 2008. Show all posts
Showing posts with label visual basic.net 2008. Show all posts

04 - Variables

Variables can hold data with corresponding data type. It can store numbers, text, and etc and is stored in the computer memory with unique addresses.

How to define a variable in VB.NET?

Dim i_can_hold_numbers As Integer
Dim i_can_hold_decimals As Decimal
Dim i_can_hold_one_character As Char
Dim i_can_hold_text As String

As you notice the first word I used Dim, it is called "Declare In Memory". It tells  the compiler that I will be creating a variable i_can_hold_numbers with type Integer after compilation, the compiler designates all variables giving them addresses for them to locate easily.

The second word is our variable name. In creating variable names, you follow a certain rules that is common to most of the programming languages.The two most important from them are,

  • You can't start the name with numbers , special characters and symbols
  • You can't use spaces between words, use "_" instead.


It is wrong to declare variables like this:
Dim i can hold numbers As Integer 

Dim 216i_can_hold_decimals As Integer

Dim @i_can_hold_numbers As Integer

Dim !i_can_hold_numbers As Integer

 - This will give you an error as stated above.

Now the last would be the variable type,  It tells the compiler the things it can hold. By the way, it's too length to post all variables here, so I'll just give you a link instead. You can find the list of variables here http://en.wikibooks.org/wiki/Visual_Basic_.NET/Variables

Adding values to the variable

For numbers:
variable_name = value   

For strings:
variable_name = "value"   

Notice that adding numeric values just only need the value itself like 23, 1000, 10.50 while strings need an opening  and closing double quote that reminds the compiler that the value is in the form of a string like "I am a string".

i_can_hold_numbers = 15
i_can_hold_text = "This is a string."

To add some information about variables, it is where you store values temporarily and is often subject for checking, especially when working with the database(Intermediate level,  will be posted soon), before taking some actions,  it is a need to verify each controls (Textbox, Button, Listview, etc.) if the contents may contain data or codes that is harmful to the database like SQL Injections.

It is also used for the default settings of the application, its window size and more.

see http://en.wikibooks.org/wiki/Visual_Basic_.NET/Variables for other declaration and assignment of value.

Now, you learned the basics of variables, we are ready to use them in our projects in the next article. See you soon. :D

Other variable declaration types other than "Dim" also known as "Access Levels"


  • Private variable_name As variable_type
  • Public variable_name As variable_type

Dim - Declare variable within the procedure, function or class.
Public - This variable is accessible in all class, procedure and functions of your project.
Private -  This variable is accessible within the procedure, function or class.


Using constants

Dump text


Next topic is about "Loop Statements".

01 - Downloading Visual Basic.NET

Downloading Visual Basic.NET


To start our adventure, I'll give you links for what we would need as we develop programs. In most cases, VB 2010 Express Edition is what we'll use 'cause it's free if don't have enough money to buy premium edition. Express Editions are enough to work the job disregarding reports and other features which were removed.

List of vb.NET installers depending on your processor's speed :


If you have faster processor speed, you can download Visual Basic 2010 Express Edition.

If you have a slower processor speed, you can download Visual Basic 2008 Express Edition.
Scroll down and look for "Visual Basic 2008 Express Edition with SP1",  then choose your language and click"Free Download"


But still it doesn't matter of what version you will install 'cause what we will do in our journey covers the basics of VB.NET, it a step in developing larger application. Coding is available to both editions although we can observe slight changes in coding, but don't worry, you can post here and I'll try best to answer all of  your questions. :D

Move to Lesson 02 - Creating new projects