introduction to visual basic .net
DESCRIPTION
Introduction to Visual Basic .NET. Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI. Topics. Introduction to VB .Net Data types and Operators in VB .Net Conditions (If Else, Select Case) Loops (Do While, Do Until, For) Classes, Objects Sub routines and Functions - PowerPoint PPT PresentationTRANSCRIPT
Introduction to Visual Basic .NET
Prepared by: Ahmad Ramin RahimeeAssistant ProfessorICTI
Topics• Introduction to VB .Net• Data types and Operators in VB .Net• Conditions (If Else, Select Case)• Loops (Do While, Do Until, For)• Classes, Objects• Sub routines and Functions• Windows Application
Introduction
• VB .Net is developed by Microsoft• It is Visual Basic for .Net Platform• Ancestor of VB .Net is BASIC• In 1991, Microsoft added visual components to
BASIC and created Visual Basic• After the development of .Net, VB was added
with more set of controls and components and thus evolved a new language VB .Net
Features of VB .Net
• Object Oriented Language
• We can drag controls from the tool bar and drop them on the form and write code for the controls
• Runs on the CLR (Common Language Runtime)
Data types and Operators in VB .Net
• Data types– Integer, string, single, double, boolean, char
• Declaring a variable– DIM i as Integer– DIM name as string
• Operators– Arithmetic (+,-,*,/,Mod)– Logical (Or, And, Not)– Relational (=,<>,<,<=,>,>=)
If Else
If (Condition)ThenStatements executed if condition is trueElseStatements executed if condition is falseEndIf
We can also have Else If block in If Else statements
Select Case
Select Case var
Case 1
stmt1 // executed if var = 1
Case 2
stmt2 // executed if var = 2
Case Else
stmt3 // executed if var is other than 1 and 2
End Select
For Loop
For <<var>> = start To end Step <<val>>Statements
Next
EgFor I = 1 To 10 Step 2
Console.WriteLine(I)NextHere the values printed will be 1,3,5,7,9
Do While Loop
1. Do While(a<>0)Console.Writeline(a)a = a – 1Loop
2. Do Console.Writeline(a)
a = a – 1 Loop While(a<>0)
Class
• Software structure that is important in Object Oriented Programming
• Has data members and methods
• Blue print or proto type for an object
• Contains the common properties and methods of an object
• Few examples are Car, Person, Animal
Object
• Instance of a class
• Gives Life to a class
• Ahmad is an object belonging to the class Person
• Ford is an object belonging to the class Car
• Jimmy is an object belonging to the class Animal
Classes vs Modules
• Classes– classes can be instantiated as objects– Object data exists separately for each instantiated object.– classes can implement interfaces.– Members defined within a class are scoped within a specific instance of the
class and exist only for the lifetime of the object.– To access class members from outside a class, you must use fully qualified
names in the format of Object.Member.
• Modules– Modules cannot be instantiated as objects, because there is only one copy of
a standard module's data, when one part of your program changes a public variable in a standard module,
– Members declared within a module are publicly accessible by default.– It can be accessed by any code that can access the module.– This means that variables in a standard module are effectively global variables
because they are visible from anywhere in your project, and they exist for the life of the program.
Subroutines and Functions
• Subroutines– Does not return any value– Can have zero or more parameters
• Functions– Always Returns some value– Can have zero or more parameters
Windows Application
• File -> New -> Project
• Select Language as VB .Net
• Select .Net template as Windows Application
• Give the path where the application need to be saved
• A application opens up with a Form
Forms and other controls
• Form is a container for other controls• We can place the following in a form
– Label– Text Box– Check Box– Radio Button– Button– Date Picker– And more…
Properties and Events• Every Control has a set of properties, methods
and events associated with it• Eg Form
– Properties• Name (program will use this name to refer)• Text (title of the form)
– Methods• Show• Hide• Close
– Events• Load• UnLoad