Visual Basic.NET Preview David Stevenson Consulting Software Engineer, ABB

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
Visual Basic.NET A look into the.NET Programming Model Bryan Jenks Integrated Ideas ©2005.
Visual Basic.NET Comprehensive Concepts and Techniques What’s new in VB.NET adapted from a presentation on Introduction to Visual Basic.NET by Jeff Quasney.
12-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
ITEC200 – Week03 Inheritance and Class Hierarchies.
More about classes and objects Classes in Visual Basic.NET.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
VB Classes ISYS 573. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
VB Classes ISYS 512. Adding a Class to a Project Project/Add Class –*** MyClass is a VB keyword. Steps: –Adding properties Declare Public variables in.
Object Oriented Programming using VC++. Introduction Program – Set of instruction written in a high level language High level language used for writing.
Object-Oriented Programming in Visual Basic.NET. Overview Defining Classes Creating and Destroying Objects Inheritance Interfaces Working with Classes.
Visual Basic.NET A look into the.NET Programming Model Bryan Jenks Integrated Ideas ©2005.
To define a class in Visual Basic.NET, you can follow this general procedure: 1. Add a class to the project. 2. Provide an appropriate file name for.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Apply Sub Procedures/Methods and User Defined Functions
Overview of Microsoft.Net and Vb.Net ITSE 2349 Spring 2002 Material from Microsoft.Net an Overview for ACC faculty by Stuart Laughton and Introduction.
Inheritance Chapter 14. What is inheritance?  The ability to create a class from another class, the “parent” class, extending the functionality and state.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Eric Vogel Software Developer A.J. Boggs & Company.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Module 7: Object-Oriented Programming in Visual Basic .NET
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Chapter 9: Getting Comfortable with Object- Oriented Programming.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Programming Pillars Introduction to Object- Oriented Programming.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Chapter Eleven Classes and Objects Programming with Microsoft Visual Basic th Edition.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Applications Development
CSCI 3327 Visual Basic Chapter 3: Classes and Objects UTPA – Fall 2011.
Chapter 6 OOP: Creating Object-Oriented Programs Programming In Visual Basic.NET.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
CIS162AD Inheritance Part 3 09_inheritance.ppt. CIS162AD2 Overview of Topics  Inheritance  Virtual Methods used for Overriding  Abstract Classes and.
VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Introducing ASP+ Scott Mitchell
Object Oriented Programming
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
1 C# / VB.NET Language Primer Chris J.T. Auld Microsoft MVP, Mobile Devices Managing Director Kognition Consulting Limited.
Object-Based Programming in VB.NET. Must Understand Following: Encapsulation Information hiding Abstract Data Type Class, Instance, Reference Variable.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
ILM Proprietary and Confidential -
Object-Oriented Programming: Classes and Objects Chapter 1 1.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
These materials where developed by Martin Schray
Object-Oriented Programming: Classes and Objects
Microsoft Visual Basic 2005: Reloaded Second Edition
CS360 Windows Programming
VISUAL BASIC.
Features of OOP Abstraction Encapsulation Data Hiding Inheritance
Object-Oriented Programming: Classes and Objects
Methods.
A look into the .NET Programming Model
C++ Object Oriented 1.
Presentation transcript:

Visual Basic.NET Preview David Stevenson Consulting Software Engineer, ABB

How to Get Visual Basic.NET w Requires Windows 2000, IE 5.5 (helpful to install IIS 5 on Win2K Pro) w NET Overview: msdn.microsoft.com/netmsdn.microsoft.com/net w Download NET: lt.asp?URL=/code/sample.asp?url=/msdn- files/027/000/976/msdncompositedoc.xml lt.asp?URL=/code/sample.asp?url=/msdn- files/027/000/976/msdncompositedoc.xml

Visual Basic.NET Goals w Rapid Application Development of Enterprise Web Applications w Language Interoperability w Improved Object Oriented Features

Modern Language Features w Free Threading w Structured Exception Handling w Type Safety w Shared Members w Initializers

Object Oriented Features w Inheritance w Encapsulation w Overloading w Polymorphism w Parameterized Constructors

Disclaimer w Syntax subject to change in released product. w Most of the following is a summary of Microsoft’s article: Visual Studio Enables the Programmable Web. Examples may be changed slightly.

OOP: Inheritance w Ability to reuse code via Inherits keyword. w Derived class inherits all methods and properties of the base class. w Derived class can override methods defined in the base class using the Overrides keyword. w The derived class can extend the base class by adding new methods and properties.

Inheritance Example Public Class MyBaseClass Function GetCustomer () Console.WriteLine ( "MyBaseClass.GetCustomer" ) End Function End Class Public Class MyDerivedClass : Inherits MyBaseClass Function GetOrders ()... End Function End Class Public Module modmain Sub Main() Dim d As MyDerivedClass d.GetOrders () End Sub End Module

Overrides Example Class MyVeryDerivedClass Inherits MyDerivedClass Overrides Function GetOrders ( )

OOP: Encapsulation w New Protected keyword. w Hides properties/methods except for derived classes. Protected cName as string Protected Function ChangeName ( NewName ) Me.cName = NewName End Function

OOP: Overloading w VB6: Overloading via Implicit Auto- Conversion was potentially dangerous. w VB.NET: Creating two or more functions with the same name, but with different function signatures (parameters). w Overloaded functions can process data differently.

Overloading Example Overloads Sub Display ( theChar As Char ) … Overloads Sub Display ( theInteger As Integer ) … Overloads Sub Display ( theString As String ) …

OOP: Polymorphism w Ability to process an object differently depending on its data type or class. w Ability to redefine methods for derived classes.

Polymorphism Example Class Employee Overridable Function PayEmployee () As Decimal PayEmployee = Hours * HourlyRate End Function End Class Class CommissionedEmployee Inherits Employee Overrides Function PayEmployee ( ) As Decimal PayEmployee = BasePay + Commissions End Function End Class

OOP: Parameterized Constructors w VB6: Unparameterized Class_Initialize w VB.NET: Allows the creation of a new instance of a class while passing arguments for initializing the data of the new class. w VB.NET: Simultaneous creation and initialization of an object instance.

OOP: Parameterized Constructors Public Class Test Private i as Integer Overloads Public Sub New() MyBase.New i = 321 End Sub Overloads Public Sub New ( ByVal par as Integer ) MyClass.New() i = Par End Sub End Class

Interfaces w Abstract classes without implementation. w Can inherit from other interfaces. w Concrete classes can singly inherit, but have multiple interface implementations.

Interface Example Part 1 Public Interface IDog Function Barks ( ByVal strBark As String ) End Interface Public Interface IDog2 : Inherits IDog Function Bites ( ByVal intNumBites As Integer ) End Interface

Interface Example Part 2 Public Class Dogs Implements IDog Implements IDog2 Public Function Bites ( ByVal intNumBites As Integer ) _ Implements IDog2.Bites Console.WriteLine ( "is worse than {0} bites.", intNumBites ) End Function Public Function Barks ( ByVal strBark As String ) _ Implements IDog.Barks Console.Write ( "A Dog's bark {0} ", strBark ) End Function End Class

Free Threading w Concurrent processing improves scalability. w Can start a thread and run asynchronously.

Free Threading Example Sub CreateMyThread ( ) Dim b As BackGroundWork Dim t As Thread Dim b = New BackGroundWork () Set t = New Thread ( New ThreadStart ( AddressOf b.DoIt ) End Sub Class BackGroundWork Sub DoIt ( ) … End Sub End Class

Structured Exception Handling w VB6: On Error Goto Problem: Goto Error Handling routine, Goto Central Error Processing Routine, Exit out of procedure. w VB.NET: Try… Catch… Finally

Structured Exception Handling Example Sub SEH ( ) Try Open “TESTFILE” For Output As #1 Write #1, CustomerInformation Catch Kill “TESTFILE” Finally Close #1 End try

Try, Catch, Finally Syntax Try tryStatements Catch exception1 [ As type ] [ When expression ] catchStatements [ Exit Try ] Catch exception2 [ As type ] [ When expression ] catchStatements [ Exit Try ] Finally finallyStatements End Try

Type Safety w VB6: Implicit Auto-Conversion on subroutine/function calls. Fails during run- time if data loss occurs. w VB.NET: Option Strict generates compile- time errors if a conversion is required. Option Strict Off.

Data Type Changes w Decimal data type replaces Currency data type. w Long is 64 bits. Integer is 32 bits. Short (new) is 16 bits.

Shared Members w Data and method members of classes that are shared by all instances of a class. w A shared data member is one that all instances of a class share. w A shared method is a method that is not implicitly passed an instance of the class. (consequently, access to class data members is not allowed).

Initializers w Initialization of variables on the lines they are declared. Dim X As Integer = 1 w Equivalent to: Dim X As Integer X = 1 w VB6 Recommendation: Dim X As Integer : X = 1

Namespaces w For organizing code hierarchically. w Example: Namespace UserGroups.NewYork.Rochester.VDUNY... Insert your code here End Namespace

Namespaces w Always public. w Components within the namespace may have Public, Friend or Private access. w Default access type is Friend. w Private members of a namespace are accessible only within the namespace declaration they were declared in.

Imports Statement w Imports namespace names from referenced projects and assemblies. w Syntax: Imports [aliasname = ] namespace Imports System Imports Microsoft.VisualBasic

Common Language Run-Time w System.* w “This changes everything.” Dodge Intrepid Commerical

Hello World! ' Allow easy reference System namespace classes Imports System ' Module houses the application’s entry point Public Module modmain ' "Main" is application's entry point Sub Main() ' Write text to the console Console.WriteLine ("Hello World using Visual Basic!") End Sub End Module

Migrating from VB6 or VBScript to VB.NET w Following information from A Preview of Active Server Pages+, Appendix B, Moving from VBScript or VB6 to VB7 w Set and Let keywords no longer supported in VB.NET. w Set objVar = objRef ‘ VB6 w objVar = objRef‘ VB.NET w Class property syntax changes in VB.NET.

VB 6 Class Property Syntax Private mstrString As String Public Property Let MyString ( ByVal NewVal As String ) mstrString = NewVal End Property Public Property Get MyString () As String MyString = mstrString End Property

VB.NET Class Property Syntax Private mstrString As String Public Property MyString As String Get MyString = mstrString End Get Set mstrString = Value End Set End Property

ReadOnly and WriteOnly Properties in VB.NET Private mstrReadOnlyString As String ReadOnly Public Property MyReadOnlyString As String Get MyReadOnlyString = mstrReadOnlyString End Get End Property

Method, Function and Subroutine Calls Require Parenthesis w VB.NET requires parenthesis around method, function and subroutine call parameters. MyFunction ( “Param1”, 1234 ) objRef.MyMethod ( “Param1”, “Param2” ) Response.Write ( “ Some Text ” ) w VB6: Use: Call MyFunction ( “par1” )

Parameters Default to ByVal w VB.NET defaults to ByVal for all parameters that are intrinsic data types. w Previously(VB6), the default was ByRef. w VB6 Recommendation: Explicitly declare all parameters to ByVal or ByRef. w References to objects, interfaces, array and string variables still default to ByRef.

Declarations in VB.NET w Variables declared in the same statements must be the same type. No longer allowed: Dim a As Integer, b As String w Variables can be initialized in the same statement they are declared: Dim a As Integer = 123 Dim intArray ( 3 ) = ( 12, 34, 56 )

Default Values and Optional Parameters w Default values can be supplied in function parameters. Sub MySubr ( ByVal intParam1 As Integer = 123 ) w Optional parameters must always supply a default value. Function MyFunction ( Optional ByVal strParam As String = “MyString” ) w IsMissing keyword is no longer supported.

Explicit Casting Now Required w VB6 Sometimes did implicit auto- conversion of data types. w VB.NET now requires explicit casting. Response.Write ( CStr ( intLoop ) ) Trace.Write ( CStr ( intLoop ) )

Shorthand assignments w VB6: intVar = intVar + 1 w VB.NET: intVar += 1 intVar -= 1 intVar *= 2 intVar /= 2

Short Circuited Conditional Statements w Conditional expressions with And or Or: if first test fails, following expressions won’t be executed: if ( a = b ) And ( c = d ) Then … If a is not equal to b, then the test for c = d will not be executed.

References w Visual Studio Enables the Programmable Web, logy/language.asp logy/language.asp w Joshua Trupin, The Future of Visual Basic: Web Forms, Web Services, and Language Enhancements Slated for Next Generation, vbnexgen/vbnexgen.asp vbnexgen/vbnexgen.asp

References w Introducing Win Forms, forms.asp forms.asp w Visual Studio Enables the Programmable Web Web Forms, bforms.asp bforms.asp

References w Richard Anderson, Alex Homer, Rob Howard, Dave Sussman, A Preview of Active Server Pages +, Appendix B, Moving from VBScript or VB6 to VB7.A Preview of Active Server Pages +,

Resources w Microsoft.NET & ASP+ Resources and Information, w News Server: news.devx.com News Group: vb.vb7 w News Server: msnews.microsoft.com News Group: microsoft.public.net.*