Title: VB'NET
1Best Practices for Upgrading VB 6.0 Projects to
VB.NET Peter Ty Developer Evangelist .NET and
Developer Group
2Agenda
- Introduction to VB.NET
- Upgrading to VB.NET
- Leveraging Existing Code
- Architectural Guidance
- Programming Recommendations
- Taking the Next Step
3Introduction to VB.NETWhat is VB.NET?
- Next Generation of Visual Basic
- Two New Forms Packages
- Removed Legacy Keywords
- Improve Type Safety
- Exposing Low-Level Constructs for Advanced
Developers - Fully Integrated With Other Visual Studio.NET
Languages
4Introduction to VB.NETDesign Goals of VB.NET
- Rapid .NET Application Creation
- Deliver the features you requested
- Modernize
- Simplify
- Reduce Programming Errors
- Solve the deployment problem
- Provide full access to the .NET Frameworks
5Introduction to VB.NETWhy is VB.NET not 100
compatible?
- Two Design Issues
- Retrofit existing code
- Building new code from ground up
- Interoperability
- A major goal to ensure Visual Basic code could
fully interoperate with C or VC - VB.NET is a true Object-Oriented Language
- Removed unintuitive and inconsistent features
6Introduction to VB.NETUpgrade Roadmap
- Upgrading Is Not A Requirement
- Leave Existing Code in VB 6.0
- Continue developing in VB 6.0
- Or interoperate between VB 6.0 and VB.NET
- Upgrade to VB.NET
- Considerations
- Application Architecture and Technologies
- Maintenance or New Development
7Introduction to VB.NETReasons To Upgrade
- Maximized Productivity
- Task List, Class View
- New project types
- NT Services
- Console Apps
- Error checking as-you-type
- First Class Object-Oriented Constructs
- Inheritance
- Structure exception handling
- Parameterized constructors
8Introduction to VB.NETReasons To Upgrade
- Windows Forms
- Visual inheritance
- Control anchoring, in-place menu editor
- Connected and disconnected databinding
- Web And Server Features
- Web forms
- Web services
- RAD for the server
- Better Deployment
- No DLL
- Builds .msi and .cab setup programs
9Introduction to VB.NETReasons To Upgrade
- Power Features
- Multi-threading
- Debugging across all languages
- Built From The Ground-up on .NET Framework
- Direct access to .NET classes
- Code access security
- ADO.NET and XML
10Agenda
- Introduction to VB.NET
- Upgrading to VB.NET
- Leveraging Existing Code
- Architectural Guidance
- Programming Recommendations
- Taking the Next Step
11Upgrading to VB.NETUsing The Upgrade Wizard
- Included With Visual Basic.NET
- Upgrades VB 6.0 Projects Opened in VB.NET
- Creates new Visual Basic.NET project
- Existing VB 6.0 project left unchanged
- Upgrade Tool Focus
- Language syntax changes
- VB 6.0 Forms, user controls
- Middle Tier Components
- WebClasses
12Upgrading to VB.NETManual Upgrade
- ActiveX Documents
- DHTML ActiveX Designer
- DAO and RDO Data Binding
- OLE, Shape Control
- Non horizontal, vertical lines
- Property Pages
- Add-In Extensibility
- Language Features
- LSet, ObjPtr, VarPtr, StrPtr
- GoSub Return, Computed Goto
13Upgrading to VB.NETTODO Comments
- Assist Developers When
- Items can not be automatically upgraded
- Behavior differences
- Summarized in Upgrade Report
'VB6 Dim o As Object Set o Me.Text1 o "Hello
World"
'Visual Basic.NET Dim o As Object O
Me.Text1 'UPGRADE_WARNING Couldn't resolve
default property of object o o "Hello World"
14Demonstration 1Using Visual Basic Upgrade
Wizard Step-By-Step Upgrade Wizard
15Agenda
- Introduction to VB.NET
- Upgrading to VB.NET
- Leveraging Existing Codes
- Architectural Guidance
- Programming Recommendations
- Taking the Next Step
16Leveraging Existing CodesRuntime Type System
- CLR Compilers use the Runtime Type System to
produce type compatible components
Runtime Components
PlatformCompilers
C
VB
C
Runtime Type System
17Leveraging Existing CodesCOM Interoperability
Services
Type SystemStandard
BinaryStandard
Runtime Execution Sys
COM Binary Std
C
VB
MFC/ATL
MSVCRT
C
Runtime Type System
18Leveraging Existing CodesWhy Interop?
- Preserve/Utilize Your Investment
- No need to start over
- Continue to use exist code
- Incremental Migration Path
- Migrate your application step by step
- Reality Some Things Never Change
- Need to interop with code that cant change
19Leveraging Existing CodesBridging Different
Worlds
- Unmanaged Code
- Binary standard
- Type Libraries
- Immutable Types
- DLL Hell
- Interface based
- HResults
- Guids
- Managed Code
- Type Standard
- Metadata
- Resilient Bind
- Assemblies
- Object based
- Exceptions
- Strong Names
20Leveraging Existing CodesInterop Services
- COM Interop
- Use COM components from the runtime
- Use .NET Framework components from COM
- Platform Invoke
- Call static Entry Points in unmanaged DLLs
- Pass function pointers to unmanaged code for
callback
21Leveraging Existing CodesBi-Directional COM
Interop
- .NET to COM
- Allows .NET types to access COM types
- COM to .NET
- Allows COM types to access .NET types
.NET
COM
COM
.NET
22Agenda
- Introduction to VB.NET
- Upgrading to VB.NET
- Leveraging Existing Codes
- Architectural Guidance
- Programming Recommendations
- Taking the Next Step
23Architectural GuidanceBrowser-based Applications
- ASP.NET
- Services for all web applications
- Authentication, Caching, State Services
- Web Services
- Web Forms
- The best of Web Classes and ASP
- Separates UI and code
- Familiar development model
- Full, compiled Visual Basic language
- Target any browser on any platform
24Demonstration 2Browser Based Application
Create a Hello World Web Application
25Architectural GuidanceClient/Server Applications
- Visually Compose Business Objects
- Manage Enterprise Wide Programmer Resources
- Easy Scalable, Transacted, Cross-Machine, And
Cross-Platform Messaging - Easily Create Windows Services
- Configure And Diagnose Your Production
Applications
26Architectural GuidanceSingle-tier Applications
- Visual Inheritance
- Delivers features you have asked for
- Visual inheritance, in-place menu editor,
printing - Accessibility
- Anchoring and docking, MDI enhancements
- Interoperability through the .NET Framework
- Designed for expansion
- Extender controls
27Architectural GuidanceData Model
- Scalability, Interoperability By Default
- DataAdapter
- Pulls data into a DataSet
- Pushes data modifications back to database
- Full programmatic control over queries
- DataSet
- No knowledge (or limitation) of data source
- Disconnected and move between tiers as XML
- Program against strongly-typed objects
- Design time support for multi-tier data access
28Demonstration 3Data Model Using ADO.NET
29Architectural GuidanceWeb Services
- First VBXs, Then COM, Now Web Services
- Creation Is Easy
- WebMethod Subs and Functions
- VS automatically publishes to the Web
- Drag-And-Drop Consumption
- Discovery via Web References, Server Explorer
- As simple as calling a method
30Demonstration 4Web Service Hello World Web
Service
31Architectural GuidanceDeployment
- No More DLL Hell
- Enabled by the .NET Framework
- Side-by-side, XCOPY, no restarting IIS,
versioning - Windows Installer Technology
- Self repairing installations, advertising,
rollback, digital signing - Transacted, custom action authoring
- Remote Install Of Web Applications, Services,
Server Resources
32Agenda
- Introduction to VB.NET
- Upgrading to VB.NET
- Leveraging Existing Codes
- Architectural Guidance
- Programming Recommendations
- Taking the Next Step
33Programming Recommendations Variant to Object
- VB 6
- Variant special universal data type
- VB.NET
- Object the universal data type used by Common
Language Runtime
Dim x As Variant
Dim x As Object
34Programming RecommendationsVariant Conversion
- VB 6
- Should Var1 and Var2 be added as strings or
integers?
- VB.NET
- Avoid using variant
- Use explicit conversions
Var3 Var1 Var2
Var3 CInt(Var1) CInt(Var2)
35Programming Recommendations Integer To Short ,
Long To Integer
- VB 6
- Long 32-bit
- Integer 16-bit
- VB.NET
- Long 64-bit
- Integer 32-bit
- Short 16-bit
Dim x As Integer Dim y As Long
Dim x As Short Dim y As Integer
36Programming Recommendations Currency To Decimal
- VB 6
- Currency 64-bit hybrid
- VB.NET
- Decimal provides better accuracy
Dim x As Currency
Dim x As Decimal
37Programming Recommendations Date To Date
- VB 6
- Date stored internally in Double format
- VB.NET
- Date 64-bit integers
Dim dbl As Double Dim dt as Date dbl dt
Dim dbl As Double Dim dt as Date dbl dt.ToOADate
38Programming Recommendations Property Syntax
- VB 6
- GET, LET and SET can be declared with different
level of accessibility
- VB.NET
- GET and SET must have the same level of
accessibility
Property Get .. Public Property Let .. Friend
Property Get .. Private Property Set .. Private
39Programming Recommendations VB Forms to Windows
Forms
- VB 6
- Has own forms package for creating graphical
applications
- VB.NET
- Windows Forms generic forms package for Common
Language Runtime
Visual Basic Forms
Windows Forms
40Programming RecommendationsEarly-Binding
- VB 6
- Declaring a variable as Object datatype and
assigning it at run time
- VB.NET
- Declare variables of the appropriate object type
Dim o As Object Set o Me.Label1 o.Caption
"SomeText"
Dim o As Label Set o Me.Label1 o.Caption
"SomeText"
41Programming Recommendations Parameterless
Default Properties
- VB 6
- Declaring a variable as Object datatype and
assigning it at run time
- VB.NET
- Declare variables of the appropriate object type
MsgBox Me.Text1 rs("CompanyName") "SomeCompany"
MsgBox Me.Text1.Text rs("CompanyName").Value
"SomeCompany"
42Programming Recommendations Avoid Null
Propagation
- VB 6
- Supports Null propagation
- VB.NET
- Does not support Null propagation
- Always check for Null
V 1 Null V Null Right("SomeText", 1) V
Right("SomeText", 0)
IsNull()
43Programming RecommendationsUse Zero Bound Arrays
- VB 6
- Can define arrays with lower and upper bounds of
any whole number
- VB.NET
- Must have a lower bound of 0
- Cant use ReDim unless the variable was
previously declared
Dim a(1 To 10) As Integer Dim v ReDim v(10)
Dim b(10) As Integer ReDim b(5) As Integer
44Programming RecommendationsConstants vs.
Underlying Values
- VB 6
- Can assign any constants or values
- VB.NET
- Use constants rather than relying on their
underlying values
Me.WindowStyle 2
Me.WindowState vbMaximized
45Programming RecommendationsArrays and
Fixed-Length Strings
- VB 6
- Fixed-length strings are supported in the language
- VB.NET
- Fixed-length strings are no longer supported in
the language
Private Type MyType MyArray(5) As Integer
MyFixedString As String 100 End Type
Private Type MyType MyArray() As Integer
MyFixedString As String End Type
46Programming RecommendationsAvoid Legacy Features
- Removed from the language
- Deflttypegt
- Computed GoTo/GoSub
- GoSub/Return
- Option Base 01
- VarPtr, ObjPtr, StrPtr
- LSet
47Programming RecommendationsWindows APIs
- Most API can be used exactly as they were in VB
6.0 - Remove the As Any by replacing the Declare with
two versions - Upgrade APIs to .NET components manually
48Programming RecommendationsForms and Controls
- Does Not Support OLE Container Control
- No Shape, Line Control
- New Graphics Commands Replacing Old Form Methods
- 2 Menu Controls MainMenu and ContextMenu
- Does Not Support DDE
49Programming RecommendationsForms and Controls
- Does Not Support Form.PrintForm Method
- VB 6.0 Drag-And-Drop Properties and Methods
Cannot Be Upgraded - Clipboard Statements Cannot Be Automatically
Upgraded - Windows Forms Does Not Support Name Property
- Use Default ScaleMode Of Twips
50Agenda
- Introduction to VB.NET
- Upgrading to VB.NET
- Leveraging Existing Codes
- Architectural Guidance
- Programming Recommendations
- Taking the Next Step
51Taking The Next StepFree Threading
- All Objects Can Be Called From Any Thread
- Similar to multi-threaded appt objects
- Types Of Synchronization Mechanisms
- SyncLock control structure
- Use of framework synchronization classes
- Synchronized Context
- Only one method of the set of objects within the
same synchronized context can execute at a time - Thread Synchronized Context
- Same but methods are always executed on the same
thread
52Taking The Next StepDelegate
- Object Oriented Function Pointer
- Can Reference Both Static and Instance Methods
- Points To A Specific Method Of A Specific
Instance - Type Safe and Secure
53Taking The Next StepAttributes
- A way associating extra information with
assemblies, classes, class members, parameters,
and return types - Many Predefined Attributes
- Function ltWebPublic()gt Deposit()
- Class ltObsolete()gt HumanTeller
- ltAssembly AssemblyVersion(1.0.0)gt
- New Attributes Can Be Defined By Classes That
Inherit From System.Attribute
54Taking The Next StepStructure Error Handling
- Eliminates need for GoTo
- Throw Statement
- Generates typed exception Supports typed
exceptions - Try Construct
- Guarded code between Try and first Catch
statement - Catch Statements
- Filters on type or general condition
- Finally Block
- Always executed
55Taking The Next StepInheritance
- Inheriting Classes Easily Broken When Base Class
Changes - By Default Methods Are Not Overridable
- Overriding Is Explicit Using Overrides Keyword
- Shadows Keyword Used To Hide Inherited Members
- Classes Can Be Declared As NotInheritable
56Taking The Next StepOverloading
- Two Or More Methods With Same Name But Different
Parameter Types - Subs and Functions
- Shared and Instance Methods
- Two Or More Properties With Same Name But
Different Parameter Types - Overloading Can Be Done In Structures, Classes,
And Interfaces
57Taking The Next StepOverriding
- Overriding Replaces Inherited Implementation Of
Method Or Property - An Overriding Methods Parameter Types Must Match
Exactly - Even when cast to base class, Calling Method
Executes New Implementation (Polymorphism)
58Taking The Next StepShadowing
- Member Of Derived Class Can Shadow All Members Of
Base Class With Same Name - This is the default behavior but a warning is
generated - Shadows keyword makes it explicit
- The kinds of the members in the base and derived
classes dont matter
59Demonstration 5Inheritance and Override
Inheritance Example 1Inheritance Example 2
60Taking The Next StepReduce Programming Errors
- Parameterized constructors
- Variables can be initialized where declared
- Circular References
- Garbage collector recovers instances in reference
cycles - Decimal type replaces Currency
61Taking The Next StepObject Performance
- Reference Assignment For Arrays
- Array1 Array2
- Instance Size Much Smaller
- Faster Object Manipulation
- Faster creation
- Faster assignment
- Supports direct data member access
62Session Summary
- VB.NET offers new features
- A true object-oriented programming language
- Closely integrated with the .NET Framework
- Interoperable with existing VB 6.0 projects
63For More Information
- MSDN Web Site at
- msdn.microsoft.com
- VB.NET Upgrade Information Sites at
- msdn.microsoft.com/vstudio/nextgen/Technology/vbup
grade.asp - msdn.microsoft.com/library/techart/vb6tovbdotnet.h
tm - msdn.microsoft.com/vbasic/technical/upgrade/downlo
ad.asp
64(No Transcript)