twitter
    Find out what I'm doing, Follow Me :)

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".

03 - Working with our Projects with Windows Controls


Now that I've showed what a form would look like and set the location of toolbox for easy access to the list of controls available in Visual Basic.NET Express Edition. We are ready to start our development.

Exercise: We are going to create program that needs a user to input a character on a text box before it will display those typed character/s, the user needs to click the button.

Step 1. In toolbox, under Common controls, look for label. Click and drag it into the form.
Step 2. In toolbox, under Common controls, look for TextBox. Click and drag it into the form.
Step 3. In toolbox, under Common controls, look for Button. Click and drag it into the form.

It will look like these with step 1 to 3


Step 4. Double click the button, a form will display and type this:

What is a MsgBox? 
- It is a pop-up notification that will display a text.

Step 5. Click Debug > Start Debugging or you could just press F5 to compile and run.



Download the Project File:
http://www.mediafire.com/download.php?xtcwxt1356uo98s
Please scan before opening.

Move to Lesson 04 - Variables

02 - Creating new projects

To begin with our development, we will create a new project by clicking File > New Project
 like this picture:


Then another form will display for selecting a type of project you're going to use,
 choose Windows Form Application then click OK


Now we are ready for development, you'll notice that a square shaped object is displayed in the left corner of the screen with three buttons in upper right edge, it is where we will work most of the time. It is called Windows Form or just Form. By the way, I added a label for you to locate the form.


Click ToolBox, Then click "Auto-Hide" to display it without hiding.


Move to Lesson 03 - Working with our Projects with Windows Controls

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

Another chapter of the blog begins

As time passes by, I try to discover new things out of something what I have. I realize the content of this blog focuses in just one subject  "Music" to help this blog grow, I'll add programming tutorials for VB.NET 2010.
I'll post up a step by step tutorial for beginners and intermediate level and try my best to make it easy to understand and apply.

It encompasses subjects such as basic manipulation of controls like Textbox, Label and etc. to manipulation of data from the database using R/DBMS like Microsoft Access, Microsoft SQL Server, MySQL and etc.

Are you ready for a change? :D

Other programming languages will be posted soon.