Académique Documents
Professionnel Documents
Culture Documents
Net
(Language
Fundamentals)
A simple VB.net program
Imports System
Console.WriteLine(“HelloWorld!!!”)
End Sub
End Module
The Main() method
• A program's Main method can appear
within a Visual Basic .NET module
• Because Visual Basic .NET modules are
classes wherein everything is shared, the
Shared keyword is not used in such a
declaration as in the previous example.
Saving,Compiling and Executing
the Program
• Save the file with extension “.vb” .(Test.vb)
• Goto command window
• Compile the file :
• vbc Test.vb
• After successful compilation .EXE file is
created(Test.EXE)
• Execute the EXE file as “Test”
Compiling the code
Execution result
Creating your first VB windows
application
Solution Explorer
Properties Box
Form
Tool box
Editing project settings
Writing the first windows application
On the button click write this
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
MessageBox.Show("Hello World", _
"A first look at vb", _
MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Sub
Execution of the Program
ByVal and ByRef in VB.net
• The word ByVal is short for “By Value”
• This means passing a copy of a variable to
your Subroutine in which case changes that
are made are made to the copy and the
original will not be altered.
• ByRef is short for “By Reference”.
• This means that you are not handing over a
copy of the original variable but pointing to
the original variable.
Example
• Let us consider the example
Dim Number1 As Integer
Number1 = 10
Call IncrementVariable(Number1)
MsgBox(Number1)
-------------------------------------
Private Sub IncrementVariable(ByVal Number1 As
Integer)
Number1 = Number1 + 1
End Sub
9223372036854775807 .
Float System.Single 1.5*10-45 to 3.4*1038 (32 bit floating point
number)
Double System.Double 5.0*10-324 to 1.7*10308 (64 bit floating point
number)
Boolean System.Boolean true or false
Decimal System.Decimal 100 to 1028(96-bit signed number)
String System.String Limited by system memory (Represents a set
of unicode characters)
For startNumber = 1 To 4
Next startNumber
MsgBox answer
do loop
Do While [expression]
statements
Loop
• Eg: Dim number as Integer
number = 1
Do While number < 5
MsgBox number
number = number + 1
Loop
Do…Until loop
Do Until [expression]
statements
Loop
• Eg:
Do Until number < 5
MsgBox number
number = number + 1
Loop
For Each
For Each variable In expression
statements
Next [ variable ]
• Eg
Dim a( ) As Integer = {1, 2, 3, 4, 5}
Dim b As Integer
For Each b In a
Console.WriteLine(b)
Next
Decision constructs
If/Else statement Condition must evaluate to bool
value
If expression Then
statements
End If
also
If expression Then
statements
Else
statements
End If
Select Case statements
Dim creamcake As String
Dim DietState As String creamcake= TextBox1.Text
Select Case creamcake
Case "Eaten"
DietState = "Diet Ruined"
Case "Not Eaten"
DietState = "Diet Not Ruined"
Case Else
DietState = "Didn't check"
End Select
MsgBox DietState