VB.NET NOTES
VB.NET NOTES
Namespace declaration
A class or module
One or more procedures
Variables
The Main procedure
Statements & Expressions
Comments
Files that make up u VB project
Project (. vbp) file. One per project. ...
Form (. frm) files. One for each form in your project. ...
Binary data (. frx) files. ...
Standard Module (. bas) files. ...
Class Modules (. cls) files. ...
Resource (. res) file. ...
Windows Layout (. vbw) file.
simple code that would print the words "Hello World"
Imports System
Module Module1
'This program will display Hello World
Sub Main()
Console.WriteLine("Hello World")
Console.ReadKey()
End Sub
End Module
BASIC SYNTAX
'Public methods
Public Sub AcceptDetails()
length = 4.5
width = 3.5
End Sub
End Sub
Length: 4.5
Width: 3.5
Area: 15.75
Data Storage
Value Range
Type Allocation
Depends on
Boolean implementin True or False
g platform
0 through +/-
79,228,162,514,264,337,593,543,950,33
5 (+/-7.9...E+28) with no decimal point; 0
Decimal 16 bytes
through +/-
7.9228162514264337593543950335
with 28 places to the right of the decimal
-1.79769313486231570E+308 through -
4.94065645841246544E-324, for
negative values
Double 8 bytes
4.94065645841246544E-324 through
1.79769313486231570E+308, for
positive values
-9,223,372,036,854,775,808 through
Long 8 bytes
9,223,372,036,854,775,807(signed)
Depends on
0 to approximately 2 billion Unicode
String implementin
characters
g platform
UIntege
4 bytes 0 through 4,294,967,295 (unsigned)
r
0 through 18,446,744,073,709,551,615
ULong 8 bytes
(unsigned)
Example
The following example demonstrates use of some of the types
Module DataTypes
Sub Main()
Dim b As Byte
Dim n As Integer
Dim si As Single
Dim d As Double
Dim da As Date
Dim c As Char
Dim s As String
Dim bl As Boolean
b = 1
n = 1234567
si = 0.12345678901234566
d = 0.12345678901234566
da = Today
c = "U"c
s = "Me"
If ScriptEngine = "VB" Then
bl = True
Else
bl = False
End If
If bl Then
'the oath taking
Console.Write(c & " and," & s & vbCrLf)
Console.WriteLine("declaring on the day of:
{0}", da)
Console.WriteLine("We will learn VB.Net
seriously")
Console.WriteLine("Lets see what happens to the
floating point variables:")
Console.WriteLine("The Single: {0}, The Double:
{1}", si, d)
End If
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the
following result
U and, Me
declaring on the day of: 12/4/2012 12:00:00 PM
We will learn VB.Net seriously
Lets see what happens to the floating point variables:
The Single:0.1234568, The Double: 0.123456789012346
VB.Net - Variables
A variable is nothing but a name given to a storage area that our
programs can manipulate. Each variable in VB.Net has a specific
type, which determines the size and layout of the variable's
memory; the range of values that can be stored within that memory;
and the set of operations that can be applied to the variable.
variable_name = value;
for example,
Dim pi As Double
pi = 3.14159
Module variablesNdataypes
Sub Main()
Dim a As Short
Dim b As Integer
Dim c As Double
a = 10
b = 20
c = a + b
Console.WriteLine("a = {0}, b = {1}, c = {2}", a,
b, c)
Console.ReadLine()
End Sub
End Module
a = 10, b = 20, c = 30