introduction to visual basic .net

16
Introduction to Visual Basic .NET Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI

Upload: melanie-mueller

Post on 31-Dec-2015

22 views

Category:

Documents


1 download

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 Presentation

TRANSCRIPT

Page 1: Introduction to Visual Basic .NET

Introduction to Visual Basic .NET

Prepared by: Ahmad Ramin RahimeeAssistant ProfessorICTI

Page 2: Introduction to Visual Basic .NET

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

Page 3: Introduction to Visual Basic .NET

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

Page 4: Introduction to Visual Basic .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)

Page 5: Introduction to Visual Basic .NET

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 (=,<>,<,<=,>,>=)

Page 6: Introduction to Visual Basic .NET

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

Page 7: Introduction to Visual Basic .NET

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

Page 8: Introduction to Visual Basic .NET

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

Page 9: Introduction to Visual Basic .NET

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)

Page 10: Introduction to Visual Basic .NET

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

Page 11: Introduction to Visual Basic .NET

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

Page 12: Introduction to Visual Basic .NET

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.

Page 13: Introduction to Visual Basic .NET

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

Page 14: Introduction to Visual Basic .NET

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

Page 15: Introduction to Visual Basic .NET

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…

Page 16: Introduction to Visual Basic .NET

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