Chapter 1: Getting started
| VB.NET Version | Visual Studio Version | .NET Framework Version | Release Date |
|---|---|---|---|
| 7.0 | 2002 | 1.0 | 2002-02-13 |
| 7.1 | 2003 | 1.1 | 2003-04-24 |
| 8.0 | 2005 | 2.0 / 3.0 | 2005-10-18 |
| 9.0 | 2008 | 3.5 | 2007-11-19 |
| 10.0 | 2010 | 4.0 | 2010-04-12 |
| 11.0 | 2012 | 4.5 | 2012-08-15 |
| 12.0 | 2013 | 4.5.1 / 4.5.2 | 2013-10-17 |
| 14.0 | 2015 | 4.6.0 ~ 4.6.2 | 2015-07-20 |
| 15.0 | 2017 | 4.7 | 2017-03-07 |
| 16.0 | 2019 | 4.8 | 2019-04-18 |
| 16.9 | 2019 | 4.8 | 2020-02-19 |
| 17.0 | 2022 | 4.8 | 2022-11-08 |
| 17.1 | 2022 | 4.8 | 2023-02-21 |
| 17.2 | 2022 | 4.8 | 2023-05-23 |
Section 1.1: Hello World
First, install a version of Microsoft Visual Studio. Create a new Visual Basic Console Application project. The following code prints the string "Hello World" to the console.
Module Module1
Sub Main()
Console.WriteLine("Hello World")
End Sub
End Module
Section 1.2: Hello World on a TextBox upon Clicking of a Button
In the designer, drag one TextBox and one Button onto the form. Double-click the button to create the click event handler, then add the line that sets the TextBox text.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = "Hello World"
End Sub
End Class
Section 1.3: #Region
You can group related methods, events or properties using the #Region directive. Collapsing regions in the editor makes navigating large classes easier.
#Region "Events"
Protected Sub txtPrice_TextChanged(...) Handles txtPrice.TextChanged
' Do the ops here...
End Sub
Protected Sub txtTotal_TextChanged(...) Handles txtTotal.TextChanged
' Do the ops here...
End Sub
#End Region
Section 1.4: Creating a simple Calculator to get familiar with the interface and code
Build a basic Windows Forms calculator:
- Install Visual Studio and start a new project.
- Select Windows Forms Application from the Visual Basic templates.
- Use the Toolbox to drag the controls you need (Buttons and a TextBox for display).
- Double-click a button to create its click event and write logic that updates the TextBox.
Private Sub ButtonNumber_Click(sender As Object, e As EventArgs) _
Handles Button0.Click, Button1.Click, Button2.Click
Dim b = DirectCast(sender, Button)
TextBoxDisplay.Text &= b.Text
End Sub
Private Sub ButtonEquals_Click(sender As Object, e As EventArgs) Handles ButtonEquals.Click
Dim result = New DataTable().Compute(TextBoxDisplay.Text, "")
TextBoxDisplay.Text = result.ToString()
End Sub
Chapter 2: Declaring variables
In Visual Basic .NET, variables are used to store and manipulate data. Before you can use a variable, you must declare it by specifying its name and the type of data it will hold.
The Dim Statement
The Dim (Dimension) statement is the most common way to declare a variable. It allocates memory for the variable and defines its characteristics.
The basic syntax is:
Dim variableName As DataType [= InitialValue]
| Data Type | Description | Example Declaration |
|---|---|---|
| Integer | Stores whole numbers (no decimals) | Dim myNumber As Integer = 42 |
| String | Stores a sequence of text/characters | Dim myText As String = "Hello" |
| Double | Stores high-precision floating-point numbers | Dim myPrice As Double = 19.99 |
| Boolean | Stores true/false values | Dim isActive As Boolean = True |
| DateTime | Stores dates and times | Dim today As Date = #2026-05-22# |
Code Examples
Here is how you can declare and assign variables inside a standard console application structure:
Module Module1
Sub Main()
' Declaring variables without an initial value
Dim myNumber As Integer
Dim myText As String
' Assigning values later in the code
myNumber = 100
myText = "Visual Basic Tutorial"
' Declaring and initializing a variable on a single line
Dim itemsCount As Integer = 5
' Displaying variable values to the console
Console.WriteLine(myText)
Console.WriteLine("The number is: " & myNumber)
End Sub
End Module
Key Rules for Naming Variables
- Must begin with an alphabetic character or an underscore (_).
- Cannot contain spaces or special characters (like %, &, $, @).
- Cannot be a reserved VB.NET keyword (e.g., you cannot name a variable Dim or Sub).
- Visual Basic is not case-sensitive, meaning myNumber and mynumber refer to the exact same variable.
Chapter 3: Control Structures
Placeholder for control structures.
Chapter 4: LINQ
Placeholder for LINQ.
No comments:
Post a Comment