Powered by Blogger.
1. Please download the Setup from the link below:
Visual Studio Express 2013 for Windows Desktop (Download Link)

2. Provide the needed details (name, email and country) and then click the "Your Selection" link:

3. As soon as you start the wdexpress_full.exe the dialog below will be shown up. Optionally change the install path and check the "I agree to the License Terms and Privacy Policy" checkbox. Finally click the INSTALL link to the bottom.

4.The setup process may take for a while so please be patient:

5. Once you get the "Setup Successful!" message click the LAUNCH link (at the very bottom):

6. The new Welcome dialog will offer you to Sign in to Visual Studio which is optional so just click "Not now, maybe later".

7. After a while the new dialog will be shown up saying that it's preparing for first use.

8. Voila! Now you have the latest Visual Studio Express for Windows Desktop running on your computer. Congratulations!

9. By default you'll see the Start Page showing Start section, Recent Projects (empty as for now), Getting Started etc.

10. Please create a new project to be sure that everything is installed and working properly.


1. The New Project dialog lets you start a new project.
Use the Project Types tree view on the left to select the project category that you want. After that select a specific project type on the right (as you see we have selected the Windows Forms Application project type). Finally set the location (default is My Documents), enter a name for the new project and click OK to create the project.

new project dialog
2. The Toolbox window displays tools that you could use with the currently active document. These tools are available when you are editing an item that can contain objects such as controls and components. By the way, these tools are grouped into sections callif you right-click a certain tab and select one of the commands in the context menu.


3. The Properties window allows you to view and modify the properties of the form and of the controls that it contains.

On our screenshot you may see the Properties window displaying properties for a Button control named ButtonLogin. You can see in the figure that the Text property of this control is "Login" and that's what the button displays to the user.

In addition please note the drop-down list at the top of the window. Well that list holds the names of all of the controls on the form. To select a certain control, you can either click it on the Designer or select it from this drop-down list.

The small icons below the dropdown determine what items are displayed in the window and how they are arranged. For example if you click the leftmost button, the window lists properties grouped by category and if you click the second icon that holds the letters A and Z, the window lists the control's properties alphabetically.


4. The Solution Explorer lets you manage the files associated with the current solution. For example, in the Figure below, you could select LoginForm.vb in the Solution Explorer and then click the View Code button (the third icon from the right at the top of the Solution Explorer) to open the form's code editor.

You can also right-click an object in the Solution Explorer to get a list of appropriate commands for that object. This window makes it easier to find a command by right-clicking an object related to whatever you want to do than it is to wander through the menus.


5. The Error List window shows errors and warnings in the current project. For example, if the code contains invalid character, this list will say so. It's extremly useful as it clearly tells you the type of the error(s) showing a full description, file name, line and everything else that helps you easily find and fix the error. If you don't see the Error List it is probably hidden. You can display it by selecting the appropriate item in the View menu.


6. The Output window displays compilation results and output printed by the application. Usually an application interacts with the user through its forms and dialog boxes, but it can display information here, usually to help you debug the code. The Output window also shows informational messages generated by the IDE. For example, when you compile an application, the IDE sends messages here to tell you what it is doing and whether it succeeded.


7. The Windows Forms Designer allows you to design forms for typical Windows applications. It lets you add, size, and move controls on a form using your mouse. Together with the Properties window, it lets you view and modify control properties, and create event handlers to interact with the controls.


8. You use the Visual Basic Code Editor to write a code that responds to control events.

The most obvious feature of the code editor is that it lets you type code, but the code editor is far more than a simple text editor such as Notepad.

It provides many features to make writing correct Visual Basic code much easier. For example you can create an event handler within the code editor. The upper left part of the code editor displays a drop-down listing all the controls.

If you select a control from the list, you can then pick an event for that control from a second dropdown in the code editor's upper right. If you select an event, the code editor generates a corresponding empty event handler for you.

To make referring to the code lines easier, code editor may display line numbers too.


To switch between design and code view:

To navigate from design to code view:
1. Right click anywhere in the Designer and select "View Code"
2. Open View menu and select "View Code"
3. Right-click the form in the Solution Explorer and select "View Code"
4. Use the hotkey "Ctrl + Alt + 0"

To navigate from code to design view:
1. Right click anywhere in the Code editor and select "View Designer"
2. Open View menu and select "View Designer"
3. Right-click the form in the Solution Explorer and select "View Designer"
4. Use the hotkey "Shift + F7"
1. First way is, if you double-click a control on the Toolbox, Visual Studio places an instance of the control on the form in a default location and at a default size. Then you can use the mouse to relocate and resize the control.
2. Second way is, if you click a control in the Toolbox, the mouse cursor changes while the mouse is over the form. The new cursor looks like a plus sign with a small image of the control's Toolbox icon next to it. If you click the form, Visual Studio adds a control at that location with a default size.


Figure 1 (with selected control in the toolbox you click the form)


Figure 2 (Visual Studio adds a control at the location you've clicked)
3. Third way is, if you do add and configure control programmatically at run time:
?
1
2
3
4
5
6
7
8
9
Dim CheckBox1 As New CheckBox
Me.CheckBox1.AutoSize = True
Me.CheckBox1.Location = New System.Drawing.Point(31, 144)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(94, 17)
Me.CheckBox1.TabIndex = 4
Me.CheckBox1.Text = "Remember me"
Me.CheckBox1.UseVisualStyleBackColor = True
Me.Controls.Add(CheckBox1)
The Properties window lets you change a control's properties at design time. When you select control in a Form Designer or in the Solution Explorer, the Properties window displays the properties of that control. To change a property's value, simply click the property and enter the new value. Meaning, for most properties, you can simply click the property and type a new value for the control. However some properties are little more complex than others and provide drop-down lists or special dialogs for setting the property value.

Tip #1: If your Properties window is hidden just press F4 on your keyboard or select Properties Windows on the View menu.

Tip #2: Arranging properties alphabetically makes it easier for many developers to find the certain property.



Another way to set control's property is using Smart Tags. Many controls display a smart tag when you select them on the Designer and it looks like a little box containing a right-pointing triangle. When you click the smart tag, a small dialog appears to let you perform common tasks for the control quickly and easily.




NOTE: You may also set the control properties programmatically at run time:
?
1
2
' this code sets the checkbox's text property
Me.CheckBox1.Text = "Remember me"
As soon as you create a new project, it is ready to run.
However if you run it immediately it will display only an empty form containing no controls.
This form will compile and run smoothly because there is nothing to be debugged/validated yet.

As soon as you add some controls to your form and write appropriate code for them you will want to test your application. To do that you simply start debugging!

There are several ways to start debugging:
1. Open the Debug menu and select "Start Debugging".
2. If you’re using the Visual Basic environment settings, you can simply press F5
3. Click Debug item in the toolbar as shown on the image below:





If there are no errors your app will run shortly after you started debugging.



Please watch the Output Windows as this window displays compilation results and output produced by Debug and Trace statements.
The comments are one of the few typographic code elements that make a programs structure a bit easier to understand.
They do not execute and they are ignored by the compiler but are an important part of how you organize your code.

Generally speaking, comments can help you as well as other developers (at a later date) to understand the code purpose.

The comment starts with a single quotation mark (') and everything until the end of the line is part of the comment and as mentioned ignored by Visual Basic.

NOTE: you cannot use line continuation characters to make a multi-line comment nor you can have block comment as they are not supported in VB.NET

If you want to comment or uncomment a large block of code quickly, just select the code and then open Edit > Advanced > Comment Selection and Uncoment Slection respectively.

You should always use comments to make your code clear and understandable.

?
1
2
3
4
5
6
7
8
9
10
11
12
' checking if the username and password are valid
If Username.Text = "admin" AndAlso Password.Text = "mypwd" Then
    Dim mForm As Form = MainForm ' instantiate the MainForm
    mForm.ShowDialog() ' display the main form
    Me.Close() ' close the login form
Else
    ' incorrect username or password provided
    Username.Text = String.Empty ' reset the username textbox
    Password.Text = String.Empty ' reset the password textbox
    ' let them know that username or password is incorrect
    MessageBox.Show("Incorrect username or password. Please try again!")
A variable is an object that stores a value which can be a number, letter, string, date etc.
If a variable contains a value, the program can manipulate it. Meaning, it can perform arithmetic operations on numbers, string operations on strings (concatenate, calculate substrings, finding a match within string and so on), date operations (find the difference between two dates, add a time period to a date), and so forth.
The variable's behavior is determined by:

1. Scope - it indicates the scope levels from where the variable can be accessed (private, public etc.)
2. Data type - can be an Integer, String, Boolean etc.
3. Accessibility - determines what code in other modules can access the variable
4. Lifetime - determines how long the variable value is valid

For instance, any variable declared inside a subroutine has scope equal to the subroutine and cannot be accessed by the code outside of the subroutine.

?
1
2
3
4
5
6
7
Private Sub DoSomething()
    Dim InsideVariable As String = String.Empty;
    ' Do Something with the variable
End Sub
 
Console.Write(InsideVariable)
' ERROR: variable is not in scope (can't be accessed from outside)

In Visual Basic you use the keyword Dim to tell Visual Basic officially that you want to declare a variable.

You can avoid the Dim only if you specify Private, Public, Protected etc. however a variable delared using a Dim keyword is Private by default so the next two declarations are identical:
An arithmetic operator is a code element that performs some operation on one or more values and creates a result. Those values are called operands. For example, in the next statement, the operator is * (multiplication), the operands are A and B while the result is assigned to the variable C:
?
1
C = A * B
Here we have a table that lists the most used arithmetic operators provided by Visual Basic:
OPERATOR PURPOSE EXAMPLE RESULT
+ Addition 2 + 2 4
- Substraction 4 - 2 2
- Negation 1 operand* - 2 -2
* Multiplication 2 * 2 4
/ Division 4 / 2 2
\ Integer Division 9 \ 2 4
^ Exponentiation 2 ^ 3 2 * 2 * 2 = 8
Mod Modulus 4 Mod 2 0
Most of you are already familiar with these except maybe Modulus and Integer Division that may need a little more explanation:

As shown in the table, \ operator performs integer division and returns the result of dividing the first operand by the second, dropping any remainder.
It's very important to understand that the result is truncated toward zero, not rounded.

The Mod operator returns the remainder after dividing the operand by the second one e.g. 5 Mod 2 = 1 because 5 = 2 * 2 + 1

The following example code prints all even numbers in range 1 to 10:

?
1
2
3
4
5
6
7
For i As Integer = 1 To 10
    If i Mod 2 = 0 Then
        Console.WriteLine(i) ' an even number
    Else
        ' we do nothing as the number is odd
    End If
Next
It often happens that you need to prompt the user to enter an expected value.

You could do it using InputBox method which displays a prompt in a dialog box or using a console application using ReadLine method which reads the next line of characters.


VB.NET Console Application:

1
2
3
4
5
6
7
Dim nl As String = Environment.NewLine
' say hi and ask them for a name
Console.WriteLine("Hello there. What's your name?" + nl)
Dim input = Console.ReadLine()
' say something to the user
Console.WriteLine(nl & "Nice to meet you " & input & "." & nl)
Console.Read()

VB.NET Windows Forms Application:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Dim prompt As String = String.Empty
Dim title As String = String.Empty
Dim defaultResponse As String = String.Empty
 
Dim answer As Object
' Set prompt.
prompt = "Hello there. What's your name?"
' Set title.
title = "Getting user input"
' Set default value.
defaultResponse = "Your name here"
 
' Display prompt, title, and default value.
answer = InputBox(prompt, title, defaultResponse)
 
' Say something to the user
Messagebox.Show("Nice to meet you " & answer)
Not Is performing logical negation on a Boolean expression, or bitwise negation on a numeric expression. (For a Boolean negation, the data type of the result is Boolean. For a bitwise negation, the result data type is the same as that of expression but if expression is Decimal, the result is Long.)


1
2
Dim IsUsernameValid As Boolean
IsUsernameValid = Not (Username.Text = "admin")


And Is performing a logical conjunction on two Boolean expressions, or a bitwise conjunction on two numeric expressions. (In a Boolean comparison, the And operator always evaluates both expressions)

1
2
Dim IsUserValid As Boolean
IsUserValid = (Username.Text = "admin") And (Password.Text = "mypwd")


AndAlso Is performing short-circuiting logical conjunction on two expressions (In a Boolean comparison, AndAlso performs short-circuiting, which means that if expression1 is False, then expression2 is not evaluated.)

1
2
Dim IsUserValid As Boolean
IsUserValid = (Username.Text = "admin") AndAlso (Password.Text = "mypwd")


Or Is performing a logical disjunction on two Boolean expressions, or a bitwise disjunction on two numeric expression (In a Boolean comparison, the Or operator always evaluates both expressions)

1
2
Dim IsPasswordValid As Boolean
IsPasswordValid = (Password.Text = "mypass") Or (Password.Text = "mypwd")


OrElse Is performing short-circuiting inclusive logical disjunction on two expressions (In a Boolean comparison, OrElse performs short-circuiting which means that if expression1 is True, then expression2 is not evaluated.)

1
2
Dim IsPasswordValid As Boolean
IsPasswordValid = (Password.Text = "mypwd") OrElse (Password.Text = "mypass")


Xor Is performing a logical exclusion on two Boolean expressions, or a bitwise exclusion on two numeric expressions. (In a Boolean comparison, the Xor operator always evaluates both expressions as there is no short-circuiting counterpart to Xor, because the result always depends on both operands.)

1
2
Dim IsUsernameValid As Boolean
IsUsernameValid = (Username.Text = "admin") Xor (Username.Text = "user")
An if statement may be composed of complex expressions as well and can contain else/elseif statements to perform more complex testing.


Whenever you need to choose between executing two different blocks of code depending on the result of a Boolean expression, you use an if statement.
The syntax of an if statement is as follows:


1
2
3
4
5
6
If booleanExpression = True Then
    DoSomething()
Else
    DoSomethingElse()
End If
' NOTE: an if statement is optionally followed by an else clause

Meaning, if booleanExpression evaluates to true, DoSomething() runs; otherwise, DoSomethingElse() runs. The Else keyword and the subsequent code are as previously mentioned optional. If there is no else clause and the booleanExpression is false, execution continues with whatever code follows the if statement. Sometimes when you need to evaluate an identical expression with a different value you write a cascading if statement using ElseIf clause

1
2
3
4
5
6
7
8
9
Dim IsUsernameValid As Boolean
If Username.Text = "user" Then
    IsUsernameValid = False
ElseIf Username.Text = "admin"
    IsUsernameValid = True
Else
    IsUsernameValid = False
End If
' NOTE: an if statement is optionally followed by an ElseIf clause as well
Visual Basic provides two concatenation operators: + and &. Both join two strings together.

Because the + symbol also represents an arithmetic operator, your code will be easier to read if you use the & symbol also knows as ampersand, for concatenation.

Using & can also make your code faster and lead to fewer problems because it lets Visual Basic know that the operands are strings.




1
2
3
4
5
' make a full name concatenate the first and the last name
Dim FullName As String = String.Empty
FullName = FirstName.Text & " " & LastName.Text
' test the result
Console.WriteLine(FullName)
The String type has a built-in Length property, which returns an integer that represents the number of characters in the string (its length).
Those characters include things like spaces as well as punctuation marks.

For example the string "Hello World!" is not only 10 characters long. Rather its length is 12 because of the empty space and the exclamation mark.


this example demonstrates the Length property:


1
2
3
4
Dim MyString As String = String.Empty     
MessageBox.Show(MyString.Length) ' = 0
MyString = "Hello World!"    
MessageBox.Show(MyString.Length) ' = 12     
You often manipulate strings by using a set of characters that appears at the start, at the end, or a set that appears somewhere in between. Those sets are called substrings.


The Substring method allows you to grab a set of characters from any position in the string and can be used in two ways.

The first way is to give it a starting point/index and a number of characters to grab (length of the string data).


In this example we instruct it to start at character position 0 (the beginning of the string), and grab the next 5 characters:


1
2
3
Dim MyString As String = "Hello World!"
Dim substring As String = MyString.Substring(0, 5)
MessageBox.Show(substring) ' = Hello                 

The other way is calling Substring method with a single argument.

When you're providing only one parameter it tells the Substring to start at the given position and copy everything right up to the end of the string data.

In this example we instruct it to grab everything at the index 6 and following that index:

1
2
3
Dim MyString As String = "Hello World!"
Dim substring As String = MyString.Substring(6)
MessageBox.Show(substring) ' = World!              
The value placeholder has the next format:
{ index [, alignment ][: format_string ] }
The index value gives the index numbered (zero based) of the parameter that should be inserted in that placeholder's position.



1
2
3
Dim project As String = "World"
Dim result As String = String.Format("Hello {0}!", project)
MessageBox.Show(result) ' = Hello World!              


The alignment value is optional and it defines a minimum number of spaces the item should use.
If alignment is negative, the result is left-justified and if it's positive, the result is right-justified.

1
2
3
Dim amount As Decimal = 500
Dim result As String = String.Format("{0, -20} {1, -3} dollars", "Thanks for paying me ", amount)
Console.WriteLine(result) ' = Thanks for paying me 500 dollars            


The format_string is also optional and indicates how the item will be formatted:

1
2
3
Dim amount As Decimal = 500
Dim result As String = String.Format("{0, -20} {1, 10:c}", "Thanks for paying me ", amount)
Console.WriteLine(result) ' = Thanks for paying me      $500.00
The String.Contains method is used when you want to check whether a specified substring occurs within the string.
It returns True if the value parameter occurs within the string, otherwise it returns False.

The String.Replace method is used when you want to replace all occurences of a specified string with another specified string.
It returns new string that is same as the current string except that all instances of oldValue are replaced with newValue.
If oldValue is not found this method returns the same string unchanged.



1
2
3
4
5
6
7
Dim OriginalString As String = "Hello User"
Dim ModifiedString As String = String.Empty;
If OriginalString.Contains("Hello") Then
    ModifiedString = OriginalString.Replace("Hello", "Good Bye")
    Console.WriteLine(ModifiedString) ' = Good Bye User"
End If