Datatypesin
Datatypesin
Double 8 bytes
Integer 4 bytes
Long 8 bytes
Object Object size based on the platform such as 4
bytes in 32-bit and 8 bytes in 64-bit platform
SByte 1 byte
Short 2 bytes
Single 4 bytes
String String Datatype depend on the implementing
platform
Type Conversion Functions in VB.NET
For Example:-
Dim Roll_no As Integer
Dim Emp_name As String
Dim Salary As Double
initialize a variable at the time of
declaration
• Dim Roll_no As Integer = 101
• Dim Emp_name As String = " A S Patil "
Getting Values from the User in VB.NET
• Procedure Scope
• Module Scope
• Public Scope
Procedure (local) scope
+ X+Y
- X-Y
* X*Y
/ X/Y
\ X\Y
Mod X Mod Y
Comparison Operators
Operator Example
= (A = B)
<> (A <> B), check Non-Equality
> (A > B); if yes, TRUE,Else FALSE
< (A < B); if the condition is true, returns TRUE else FALSE
>= A >= B
<= A <= B
Xor It is an Exclusive OR Operator that represents, whether both the A Xor B is True
expression is true or false, the result is True; otherwise, the result is
False.
AndAlso It is a logical AND Operator that performs short-circuit operation A AndAlso B = False
on the variables, and if both the operands are true, the result is True
else the result is False.
*= X *= P, which is same as X = X - P
/= X /= P, which is same as X = X - P
\= X \= P, which is same as X = X - P
^= X ^= P, which is same as X = X ^ P
Operator Example
• If-Then Statement
• If-Then Else Statement
• If-Then ElseIf Statement
• Select Case Statement
• Nested Select Case Statements
If-Then Statement
• Syntax:
• If condition Then
• [Statement or block of Statement]
• End If
• Module if_statement2
• Sub Main()
• Dim no1, no2 As Integer
• Console.WriteLine("Enter any two number:")
• no1 = Console.ReadLine()
• no2 = Console.ReadLine()
• If no1 > no2 Then
• Console.WriteLine("First number is greater than second nu
mber") End If
• If no1 < no2 Then
• Console.WriteLine("Second number is greater than First
number")
• End If
• Console.WriteLine("press any key to exit...")
• Console.ReadKey()
• End Sub End Module
If-Then-Else Statement
• Syntax:
• If (Boolean_expression) Then
• 'This statement will execute if the Boolean con
dition is true
• Else
• 'Optional statement will execute if the Boolea
n condition is false
• End If
If-Then-ElseIf statement
• Syntax
• If(condition 1)Then
• ' Executes when condition 1 is true
• ElseIf( condition 2)Then
• ' Executes when condition 2 is true
• ElseIf( boolean_expression 3)Then
• ' Executes when the condition 3 is true
• Else
• ' executes the default statement when none of the ab
ove conditions is true.
• End If
Select Case Statement
• Select Case [variable or expression]
• Case value1 'defines the item or value that you want to match
.
• // Define a statement to execute
•
• Case value2 'defines the item or value that you want to match
.
• // Define a statement to execute
•
• Case Else
• // Define the default statement if none of the conditions is tru
e.
• End Select
Programs
• Write a program to use the If-Then-ElseIf Statement for calculating the
division obtained by the student. Also, take the marks obtained by the
student in 5 different subjects from the keyboard.
• Write a program to print the larger and smaller of the two numbers.
• Write a program to check whether the number is even or odd.
• Write a program to display the Days name using the select case statement
in VB.NET.
• Write a program to perform an arithmetic operation using the Select case
statement in VB.NET.
• Write a simple program to print a table in the VB.NET.
• Write a simple program to print subject names using For Each loop in
VB.NET.
• Write a program to print the sum of digits of any number using while End
loop in VB.NET.
Loops in Vb.Net
1. For Next Loop
• Imports System
• Module Number
• Sub Main()
• Console.Write(" The number starts from 1 to 10
" & vbCrLf)
• For i As Integer = 1 To 10 Step 1
• Console.WriteLine(" Number is {0} ", i)
• Next
• Console.WriteLine(" Press any key to exit... ")
• Console.ReadKey()
• End Sub
• End Module
For Each Loop
• Syntax:
• For Each var_name As [ DataType ] In Collectio
n_Object
• [ Statements to be executed]
• Next
Example
• Imports System
• Module For_Each_loop
• Sub Main()
• Dim An_array() As Integer = {1, 2, 3, 4, 5}
• Dim i As Integer
• For Each i In An_array
• Console.WriteLine(" Value of i is {0}", i)
• Next
• Console.WriteLine("Press any key to exit...")
• Console.ReadLine()
• End Sub
• End Module
While End Loop
• Syntax:
• While [condition]
• [ Statement to be executed ]
• End While
• Imports System
• Module while_ex
• Sub Main()
• Dim x As Integer
• x=1
• While x <= 10
• Console.WriteLine(" Number {0}", x)
• x=x+1
• End While
• Console.WriteLine(" Press any key to exit...")
• Console.ReadKey()
• End Sub
• End Module
Do Loop
• Do
• [ Statements to be executed]
• Loop While Boolean_expression
• // or
• Do
• [Statement to be executed]
• Loop Until Boolean_expression