• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Best practices for upgrading vb 6.0 projects to vb.net
 

Best practices for upgrading vb 6.0 projects to vb.net

on

  • 2,949 views

Best Practices for Upgrading VB 6.0 Projects to VB.NET

Best Practices for Upgrading VB 6.0 Projects to VB.NET

Statistics

Views

Total Views
2,949
Views on SlideShare
2,949
Embed Views
0

Actions

Likes
0
Downloads
60
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • KEY MESSAGE: Presentation Title SLIDE BUILDS: None SLIDE SCRIPT: Hello and Welcome to this MSDN session on best practices for upgrading Microsoft® Visual Basic® 6 Projects to Microsoft® Visual Basic® .NET. My name is {insert name} SLIDE TRANSITION: What this presentation covers. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: What the session covers. SLIDE BUILDS: None SLIDE SCRIPT: We’re going to cover a quite few things in this session. Our first job is to understand the upgrading roadmap. We’ll cover which projects are best for upgrading, and which projects are best left in Visual Basic 6.0. We’ll take several Visual Basic 6 projects, and step through the process of how to upgrade them to Visual Basic.NET. We’ll also cover how to leverage your existing code in the Microsoft® .NET world by using COM interop. Finally, we’ll do some side-by-side comparisons between Visual Basic 6 and Visual Basic.NET so we can understand how Visual Basic.NET’s new features work. SLIDE TRANSITION: Session Pre-requisites. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Session prerequisites SLIDE BUILDS: None SLIDE SCRIPT: Here are the session prerequisites. First, you should have some experience developing with Visual Basic 6.0. Both Visual Basic 6 and Visual Basic.NET are object-oriented languages, Visual Basic.NET even more so, so understanding component-based or object-oriented development is very important. We’ll take a look at several Microsoft® Windows® programs in both Visual Basic 6 and Visual Basic.NET so understanding Windows development is also a prerequisite. Finally, some introductory or basic knowledge of Visual Basic.NET or the .NET platform will be helpful. SLIDE TRANSITION: So why this presentation. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The purpose of this session. SLIDE BUILDS: None SLIDE SCRIPT: So, why this presentation? The major goal is simply to explain how to upgrade your existing Visual Basic 6.0 applications to this brave new world of .NET. We’ll also want to explain some of the new features of Visual Basic.NET and compare and contrast them with Visual Basic 6.0. SLIDE TRANSITION: Demonstrations ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: This session has 5 demonstrations all of which cover some aspect of upgrading Visual Basic 6.0 applications to Visual Basic.NET. SLIDE BUILDS: None SLIDE SCRIPT: As a great as theory is, you’re always going to want to see some real code in action and this session won’t disappoint. We have five demos planned. First, we’ll take a small Visual Basic 6 application and upgrade it to Visual Basic.NET using the Upgrade Wizard. We’ll do this step-by-step, so you can see how the Wizard works and why it made the changes it did. Second, we’ll take a look at an n-tiered application and upgrade the presentation layer to Visual Basic.NET, keeping the existing business logic in Visual Basic 6. This is a great demo because it demonstrates upgrading Windows UI code and using COM interop. Third, we’ll do a side-by-side comparison of drag-and-drop code in Visual Basic 6 and Visual Basic.NET, showing you what’s changed and what’s similar. Fourth, we’ll show you how to upgrade Win32 API calls. This is a great demo because we show you how to do this step by step using the Browse for Folder API call as an example. This is real-life code that you can easily reuse in your own applications. If you were to walk out of here today and the only thing you remembered was this code, then that alone would be worth the price of admission. Finally, we’ll take a look at how to print in Visual Basic.NET. Printing is one of the things that has changed significantly between Visual Basic.NET and Visual Basic 6 so you don’t want to miss that. SLIDE TRANSITION: Agenda ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Today’s agenda. SLIDE BUILDS: None SLIDE SCRIPT: Here is our agenda, which closely matches the demonstrations. First, we’ll give a brief introduction to Visual Basic.NET. This includes what’s new, what’s changed and how you take advantage of the .NET platform. Next, we’ll cover the Upgrade Wizard, and how to upgrade Visual Basic 6.0 applications to Visual Basic.NET. We’ll explain how to upgrade your Windows forms, and how to use COM interop to leverage your existing Visual Basic 6 code base on the .NET platform. Then we’ll take a closer look at some of the things that have changed in Visual Basic.NET, such implementing drag and drop, calling Win32® APIs and finally how to print text and graphics in .NET. SLIDE TRANSITION: Intro to Visual Basic.NET ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: What is Visual Basic.NET as compared to previous versions of VB. SLIDE BUILDS: None SLIDE SCRIPT: Visual Basic.NET is the next version of Visual Basic. Rather than simply adding some new features to Visual Basic 6.0, Microsoft has reengineered the product to make it easier than ever before to write distributed applications such as Web and enterprise n-tier systems. Visual Basic.NET has two new forms packages (Windows Forms and Web Forms); a new version of ADO for accessing disconnected data sources; and the language itself has been streamlined, removing legacy keywords, improving type safety, and exposing low-level constructs advanced developers require. These new features open new doors for the Visual Basic developer: With Web Forms and Microsoft® ADO.NET you can now rapidly develop scalable Web sites; with inheritance, the language now truly supports object-oriented programming; Windows Forms natively supports accessibility and visual inheritance; and deploying your applications is now as simple as copying your executables and components from directory to directory. Visual Basic.NET is now fully integrated with the other Visual Studio® .NET languages: Not only can you develop application components in different programming languages, your classes can now inherit from classes written in other languages using cross-language inheritance. With the unified debugger, you can now debug multiple-language applications, irrespective of whether they are running locally or on remote computers. Finally, whatever language you use, the .NET Framework provides a rich set of APIs for Windows and the Internet. SLIDE TRANSISTION: Design Goals for VB.NET ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Visual Basic.NET had some very clear design goals SLIDE BUILDS: None SLIDE SCRIPT: There are several design goals for Visual Basic.NET: Provide rapid .NET application creation Deliver the features you requested Modernize the Visual Basic programming language Simplify the Visual Basic programming syntax Reduce programming errors Solve deployment problem Provide full access to the .NET Framework SLIDE TRANSISTION: Why is VB.NET not 100% compatible. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Why is VB.NET not 100% compatible with VB 6. SLIDE BUILDS: None SLIDE SCRIPT: There were two options to consider when designing Visual Basic.NET - retrofit the existing code base to run on top of the .NET Framework, or build from the ground up, taking full advantage of the platform. To deliver the features most requested by customers (such as inheritance and threading), to provide full and uninhibited access to the platform, and to ensure that Visual Basic moves forward into the next generation of Web applications, the right decision was to build from the ground up on the new platform. For example, many of the new features found in Windows Forms could have been added to the existing code base as new controls or more properties. However, this would have been at the cost of all the other great features inherent to Windows Forms, such as security and visual inheritance. SLIDE TRANSISTION: Continued: Why is Visual Basic not 100% compatible. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Why is Visual Basic.NET not 100% compatible SLIDE BUILDS: None SLIDE SCRIPT: One of our major goals was to ensure Visual Basic code could fully interoperate with code written in other languages such as C# or Microsoft® Visual C++®, and enable the Visual Basic developer to harness the power of the .NET Framework simply, without resorting to the programming workarounds traditionally required to make Windows APIs work. Visual Basic now has the same variable types, arrays, user-defined types, classes and interfaces as Visual C++ and any other language that targets the common language runtime; however, we had to remove some features, such as fixed-length strings and non-zero based arrays from the language. Visual Basic is now a true object-oriented language; some unintuitive and inconsistent features like GoSub/Return and DefInt have been removed from the language. The result is a re-energized Visual Basic, which will continue to be the most productive tool for creating Windows-based applications, and is now positioned to be the best tool for creating the next generation Web sites. SLIDE TRANSISTION: Upgrade Roadmap ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Upgrade Roadmap from VB 6 to VB.NET SLIDE BUILDS: None SLIDE SCRIPT: Let’s talk about the upgrade roadmap. Upgrading is not a requirement. You can leave existing code in Visual Basic 6.0 and continue developing in Visual Basic 6.0. Or, you can interoperate between Visual Basic 6.0 and Visual Basic.NET by upgrading gradually, project by project. Often this is the most recommended approach, especially with the simple projects to start off with. This gives developers a chance to familiarize themselves with the new Visual Basic.NET language, syntax and the environment. There are a number of considerations when it comes to upgrading to Visual Basic.NET. One of them is application architecture and technologies, and the other is whether the solution is in the maintenance, development or planning phase. SLIDE TRANSISTION: Reasons to Upgrade ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Why should you upgrade to VB.NET SLIDE BUILDS: None SLIDE SCRIPT: To maximize productivity, Visual Basic.NET introduces Task List and Class View. In addition to traditional EXEs and DLLs, Visual Basic.NET also offers new project types such as NT Service and Console Application. Still other new project types include Microsoft® ASP.NET Web Application and XML Web Service. What’s more, Microsoft has released the Mobile Internet Toolkit which lets you easily create powerful Web applications for mobile devices such as smart phones. Perhaps even more exciting is the .NET Compact Framework and Smart Device Extensions which let you create rich client applications on Pocket PCs, Handheld PCs and other embedded devices. Never before has Visual Basic been this powerful or flexible. Visual Basic.NET is now a first class object-oriented language, featuring: Inheritance Polymorphism Structured Exception Handling Overloading Overriding Constructors and Destructors SLIDE TRANSISTION: More reasons to upgrade ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Creating objects in Visual Basic.NET is more efficient than it was in Visual Basic 6.0. SLIDE BUILDS: None SLIDE SCRIPT: Objects are more efficient in Visual Basic.NET than they were in Visual Basic 6. For example, if you were to define an empty class in Visual Basic 6, this would consume approximately 100 bytes. In Visual Basic.NET, it’s only 8 bytes. This is because the mechanism behind how the objects work is fundamentally different. Visual Basic 6 was based on COM, which required additional overhead such as the eventing architecture and reference counting. Garbage collection runs in a background thread, so destroying objects is more efficient. Assignment is also faster in Visual Basic.NET because you don’t have to do the release (prev contents of variable) and addref (to assign new). Direct data member access couldn’t be done in Visual Basic 6. You had to make a call on a method (on public data members). Now they’re properties, so you can get direct access. SLIDE TRANSISTION: More Reasons to Upgrade ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Windows Forms and Web Forms Development and Deployment has been made easier and more productivity in VB.NEt SLIDE BUILDS: None SLIDE SCRIPT: Windows Forms Windows Forms are used to develop applications where the client is expected to shoulder a significant amount of the processing burden in an application. These include classic Win32 desktop applications, the kinds that were traditionally developed in previous versions of Visual Basic and Visual C++. Examples include drawing or graphics applications, data-entry systems, point-of-sale systems, and games. All of these applications have in common that they rely on the power of the desktop computer for processing and high-performance content display. Some Windows Forms applications might be entirely self-contained and perform all application processing on the user's computer. Games are often written this way. Others might be part of a larger system and use the desktop computer primarily for processing user input. For example, a point-of-sale system often requires a responsive, sophisticated user interface that is created on the desktop computer, but is linked to other components that perform back-end processing. Because a Windows application that uses Windows Forms is built around a Windows framework, it has access to system resources on the client computer, including local files, the Windows registry, the printer, and so on. This level of access can be restricted to eliminate any security risks or potential problems that arise from unwanted access. Additionally, Windows Forms can take advantage of the .NET GDI+ graphics classes to create a graphically rich interface, which is often a requirement for data-mining or game applications. SLIDE TRANSISTION: More Reasons to Upgrade ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Continued from previous SLIDE BUILDS: None SLIDE SCRIPT: Web Forms ASP.NET Web Forms are used to create applications in which the primary user interface is a browser. Naturally, this includes applications intended to be available publicly via the World Wide Web, such as e-commerce applications. But Web Forms are useful for more than just creating Web sites — many other applications lend themselves to a "thin front end" as well, such as an intranet-based employee handbook or benefits application. An important feature is that there is no distribution cost, since users already have installed the only piece of the application that they need— the browser. Web Forms applications are by definition platform-independent — that is, they are "reach" applications. Users can interact with your application regardless of what type of browser they have and even what type of computer they are using. At the same time, Web Forms applications can be optimized to take advantage of features built into the most recent browsers such as Microsoft Internet Explorer 5 to enhance performance and responsiveness. (In many cases, this optimization is built into the Web Forms components you are using, which can automatically detect browser levels and render pages accordingly.) Web Forms offer some features that are useful even in non-Web contexts. Because they rely on HTML, they are suitable for text-intensive applications of any sort, and especially those in which text formatting is important. Because browsers are usually limited in their access to a user's system resources, they are useful precisely in situations where you want to limit users' access to portions of your application. SLIDE TRANSISTION: Reasons to upgrade for power VB 6 users ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Power user features such as the development of multi-threaded applications, great debugging support and full access to the depth of the framework are also key reasons to upgrade. SLIDE BUILDS: None SLIDE SCRIPT: Last but not least, Visual Basic.NET offers powerful features: Miscellaneous data types Delegates, Safe Function Pointers Shared Members References and the Imports Statement Namespaces Assemblies Attributes Multithreading SLIDE TRANSISTION: Deployment has been made much easier and DLL Hell has been eliminated to a large degree. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Deployment has been made much easier for Web and Desktop applications. SLIDE BUILDS: None SLIDE SCRIPT: With Visual Basic.NET, deployment is no longer a pain. To start off with, there is no more “DLL Hell”. This is supported by the .NET Framework. The Windows Installer technology provides self-repairing installations, advertising, rollback and digital signing. Also, there is the remote install of Web applications and services, as well as server resources. SLIDE TRANSISTION: Next Agenda item ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Next Agenda item is Upgrading to Visual Basic.NET SLIDE BUILDS: None SLIDE SCRIPT: The next agenda item is upgrading to Visual Basic.NET. In this section we’ll focus on the upgrade tools. SLIDE TRANSISTION: Using the upgrade wizard ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Using the Upgrade Wizard to move from VB6 to VB.NET SLIDE BUILDS: None SLIDE SCRIPT: One of the major concerns for existing Visual Basic developers is the upgrade process. Microsoft has taken that into account and we have come up with an upgrade wizard to assist current Visual Basic developers to migrate their existing code. It is included with the Enterprise, Enterprise Architect and Professional editions of Visual Studio .NET. (It is not included with Visual Basic.NET Standard Edition.) The upgrade wizard is very simple to use and it focuses on the following: Language syntax changes Data type changes Visual Basic 6.0 Forms and controls Middle-tier Components SLIDE TRANSISTION: Manual Upgrade process ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Performing Manual Upgrades on items not automatically upgraded by the upgrade wizard. SLIDE BUILDS: None SLIDE SCRIPT: Because Visual Basic.NET is so different from Visual Basic 6.0, it is important to understand that not all the existing features are upgradeable. The following list provides the major components or features that would require manual upgrades: ActiveX Documents User Controls Web Classes DHTML ActiveX Designer DAO and RDO Data Binding OLE, Shape Control Property Pages Add-In Extensibility Language Features: LSet, ObjPtr, VarPtr, StrPtr, GoSub & Return, Computed Goto SLIDE TRANSISTION: Comments left after the upgrade. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: After the upgrade TODO’s can be found in your code where manual intervention is necessary. SLIDE BUILDS: None SLIDE SCRIPT: The purpose of the TODO comments are to assist developers when: Items can not be automatically upgraded Behavior differences exist The comments are summarized in the upgrade report, as well as integrated in the upgraded code. SLIDE TRANSISTION: First demonstration Demo 1. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: This demonstration shows how to use the Upgrade Wizard Step by Step. SLIDE BUILDS: SLIDE SCRIPT: For our first demo, let’s walk through using the Upgrade Wizard step by step and examine all the changes that it made. SLIDE TRANSITION: Next Agenda Item ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Next Agenda item upgrading Windows Forms and COM Interop SLIDE BUILDS: None SLIDE SCRIPT: The next item on the agenda covers Windows Forms applications and Com Interop. SLIDE TRANSISTION: Upgrading Windows Forms Applications ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The Upgrade Wizard upgrades Visual Basic 6.0 to .NET Windows Forms, but most applications require at least some manual upgrade work. SLIDE BUILDS: None SLIDE SCRIPT: The Upgrade Wizard will automatically upgrade your Visual Basic 6.0 forms to Visual Basic.NET Windows Forms. The Upgrade Wizard does a good job of keeping your form layout similar. Most of the properties, methods and events in Visual Basic 6 will map over to Visual Basic.NET. For example, Visual Basic 6’s Caption property now maps to Visual Basic.NET’s Text property. It works the same, it just has a new name. However, some things no longer exist in Visual Basic.NET. For example, the PrintForm method is gone and Dynamic Data Exchange (DDE) is no longer supported. In order to maintain as much compatibility as possible, the Upgrade Wizard will continue to use the same ActiveX controls as the original code base. For example, if you have a Visual Basic 6 form that hosts an ActiveX control such as Visual Basic 6’s DateTimePicker, the newly upgraded Visual Basic.NET form will also use the DateTimePicker ActiveX control. How is this possible, to use an ActiveX component inside a .NET application? This is possible using something called COM interop, which we will take a look at shortly. Some things are still supported in Visual Basic.NET where the model has changed so significantly that the Upgrade Wizard does not upgrade them. For example, printing, drag and drop and graphics code will require a manual upgrade. SLIDE TRANSISTION: Let’s take a look at COM interop… ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: COM Interop services are provided by the .NET Runtime to ease the use of legacy code. SLIDE BUILDS: None SLIDE SCRIPT: The Microsoft .NET Framework promotes interaction with COM components, COM+ services, external type libraries, and many operating system services. Data types, method signatures, and error-handling mechanisms vary between managed and unmanaged object models. To simplify interoperation between the .NET Framework components and unmanaged code and to ease the migration path, the common language runtime conceals from both clients and servers the differences in these object models. Code executing under the control of the runtime is called managed code. Conversely, code that runs outside the runtime is called unmanaged code. COM components, ActiveX interfaces, and Win32 API functions are examples of unmanaged code. SLIDE TRANSISTION: Why continue to interop with legacy code? ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Why should you continue to interop with legacy code with the advent of managed code? SLIDE BUILDS: None SLIDE SCRIPT: So why interop you ask. There are a few good reasons for interop: Preserve and utilize your current and future investment. There is no need to start over and it is possible to continue to use existing code. It is a more natural incremental migration path: to migrate your solution step-by-step. Lastly, it is reality. Some things can never change, so it is necessary to interop with code that can’t change. SLIDE TRANSISTION: Interop Services that are provided. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The available interop services for use in communicating between managed and unmanaged code. SLIDE BUILDS: None SLIDE SCRIPT: If you plan to write COM-based applications in the future, you can design your code to interoperate with managed code efficiently. You can also simplify the migration of unmanaged code to managed code with advance planning. The following recommendations summarize the best practices for writing COM types that interact with managed code. Provide Type Libraries The runtime requires metadata for all types, including COM types, in most situations. The TlbImp utility, which is included in the SDK, can convert COM type libraries to .NET Framework metadata. Once the type library is converted to metadata, managed clients can call the COM type seamlessly. In Visual Basic 6.0, the type library is typically embedded within a .DLL, .EXE, or .OCX file as a resource. Register Type Libraries To marshal calls correctly, the runtime might need to locate the type library that describes a particular type. You should use Regsvr32.exe to register the component. Use Chunky Calls Marshaling data between managed and unmanaged code has a cost. You can mitigate the cost by making fewer transitions across the boundary. Chunky interfaces that minimize the number of transitions generally perform better than chatty interfaces that cross the boundary often, performing small tasks with each crossing.
  • Explicitly Free External Resources Some objects use external resources during their lifetime; a database connection, for example, might update a recordset. Typically, an object holds onto an external resource for the duration of its lifetime, whereas an explicit release can return the resource immediately. You should provide a Close or Dispose to free the external file resource even though the file object continues to exist. Avoid Using Module Functions Type libraries can contain functions defined on a module. Typically, you use these functions to provide type information for DLL entry points. TlbImp.exe does not import these functions. Avoid Using Members of System.Object in Default Interfaces Managed clients and COM coclasses interact with the help of wrappers provided by the runtime. When you import a COM type, the conversion process adds all methods on the default interface of the coclass to the wrapper class, which derives from the System.Object class. Be careful to name the members of the default interface so that you do not encounter naming conflicts with the members of System.Object. If a conflict occurs, the imported method overrides the base class method. To prevent naming conflicts, avoid using the following names in default interfaces: Object, Equals, Finalize, GetHashCode, GetType, MemberwiseClone, and ToString. SLIDE TRANSISTION: Bi-Directional Com Interop ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Bi-Directional COM interop also exists so .NET managed code can also interop with COM based applications. SLIDE BUILDS: None SLIDE SCRIPT: Existing COM components written in Visual Basic 6.0 can still be used by managed code as middle-tier business logic or as isolated functionality. In fact, COM interop goes both ways. So not only can you access COM components from Visual Basic.NET code, you can also access Visual Basic.NET components from COM. SLIDE TRANSISTION: Demonstration #2 ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: This demonstration shows how to upgrade Windows forms and how to use COM interop to leverage existing business logic. SLIDE BUILDS: SLIDE SCRIPT: For our second demonstration, we’ll take a look at upgrading an n-tier business application written in Visual Basic 6. For demonstration purposes, there will be two tiers, a business tier and a presentation tier. The business tier is implemented as an ActiveX DLL. The presentation tier provides the user interface as a standard Windows EXE. We’ll upgrade the presentation tier from Visual Basic 6 to Visual Basic.NET and use COM interop to access the business logic. SLIDE TRANSITION: Next Agenda Item ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The next agenda item is Drag and Drop operations SLIDE BUILDS: None SLIDE SCRIPT: The next agenda item is Drag and Drop operations. Drag and Drop operations have changed in the move from VB 6 to VB.NET therefore it’s good to know some of the key differences before you upgrade. SLIDE TRANSISTION: Overview of Drag and Drop ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Visual Basic 6 had two types of drag and drop models. Visual Basic.NET simplifies this with one single way to perform drag and drop. SLIDE BUILDS: None SLIDE SCRIPT: In Visual Basic 6.0, there were two different ways to do drag and drop. The first way, available since version 1.0, is often called standard drag and drop. It was designed to support dragging and dropping controls within a single form. The advantage was that it was simple to code. The disadvantage is that it was very limited. It didn’t work across applications and it didn’t support multiple data formats. The second way to do drag and drop in Visual Basic 6 is called OLE drag and drop. This was added as a more robust way to perform drag and drop operations. It solves the shortcomings of standard drag and drop but it was a bit more complicated to code. Unfortunately, that meant that developers had two different sets of properties, methods and events to learn. What’s more, neither methodology worked well with the other. Visual Basic.NET simplifies this by standardizing on a single way to perform drag and drop. This new methodology is somewhat similar to Visual Basic 6’s OLE drag and drop but is not identical. It supports drag and drop on a single form or between different applications, and supports multiple data formats. Unfortunately, the Upgrade Wizard does not upgrade drag and drop code. This is a manual process. SLIDE TRANSISTION: Performing Drag and Drop Operations ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: To begin a drag and drop operation in Visual Basic.NET, call the source control’s DoDragDrop method. SLIDE BUILDS: None SLIDE SCRIPT: To begin a drag and drop operation in Visual Basic.NET, you call the source control’s DoDragDrop method. The DoDragDrop method accepts two parameters. The first is the data to be dragged. The second, AllowedEffects, determines the type of operations that are allowed to be performed. There are six possible effects: Copy - The data is copied to the drop target. Link - The data from the drag source is linked to the drop target. Move - The data from the drag source is moved to the drop target. Scroll - Scrolling is about to start or is currently occurring in the drop target. All - The data is copied, removed from the drag source, and scrolled in the drop target. None - The drop target does not accept the data. SLIDE TRANSISTION: Performing Drag and Drop Operations continued ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The DragEnter event begins the target control’s interaction with the drag-and-drop operation. The DragOver event lets you check to see if there is a change in the keyboard or mouse button state. SLIDE BUILDS: None SLIDE SCRIPT: When the user first drags the mouse pointer over the target control, the DragEnter event fires. The AllowedEffect parameter lets the target control examine what drag-and-drop operations are allowed by the source control. This property is read-only. The Effect property is used by the target control to set what drag-and-drop operations it allows. The DragOver event is called repeatedly as the mouse pointer is dragged around the inside of the control’s boundaries. You can use this event to check if there is a change in the keyboard or mouse button state. SLIDE TRANSISTION: Performing Drag and Drop operations continued ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The DragLeave event occurs when the drag-and-drop operation is aborted. The DragDrop event successfully completes the drag-and-drop operation. SLIDE BUILDS: None SLIDE SCRIPT: The DragLeave event fires when the user drags the mouse pointer out of the target control or the user cancels the current drag-and-drop operation. In other words, this means that the user either canceled the drag-and-drop operation or decided to drag the data to another target. The DragDrop event is raised when the drag-and-drop operation is successfully completed. This occurs when the user releases the mouse button while over the target control. The data that was dropped is contained in the Data property which is passed into the event procedure as an argument. You use the Data.GetData method to access this data. SLIDE TRANSISTION: Let’s look at some source code to see this in action. First, we’ll look at drag and drop in Visual Basic 6. Then we’ll see how the exact same application is written in Visual Basic.NET. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: This demonstration compares and contrasts how drag and drop works in Visual Basic 6 and Visual Basic.NET. SLIDE BUILDS: SLIDE SCRIPT: Now that we’ve covered the theory behind how drag and drop works in .NET, let’s take a look at some actual code. For this demonstration, we’re not going to use the Upgrade Wizard. The reason why is that the Upgrade Wizard does not upgrade drag and drop code. Upgrading is manual process. SLIDE TRANSITION: Next Agenda Item ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The next agenda item covers how to make Win32API calls from .NET. SLIDE BUILDS: None SLIDE SCRIPT: While the .NET Framework provides a great deal of base functionality in some (rare) cases you will still need to call out to certain Win32 API functions. SLIDE TRANSISTION: Calling out to Win32 API functions overview ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The Upgrade Wizard will perform some of the changes needed for Win32 API calls to work, but some changes must be made manually. SLIDE BUILDS: None SLIDE SCRIPT: Although Visual Basic 6.0 included a lot of built-in functionality, it did not provide everything. Sometimes, you had to resort to using low-level Win32 API calls to get at the functionality you needed. Visual Basic.NET still supports using the Win32 API using the Declare keyword, but there are some differences. First, some of the data types in Visual Basic have changed. In Visual Basic 6, Integer was a 16-bit value and Long was 32-bit. In Visual Basic.NET, Short is 16-bit, Integer is now 32-bit and Long is 64-bit. The good news is that the Upgrade Wizard will upgrade your data types automatically. You only really need to worry about this when writing new code. Second, As Any is no longer supported in Visual Basic.NET. As you recall, As Any allows you to pass any type of data to an API. If the wrong type were passed, the Visual Basic 6 compiler would not flag it, but at run-time your application would probably crash. One of the design goals of .NET was to be type safe. So, if you have code that uses As Any, simply declare the parameter as a specific data type. If there is an API, such as SendMessage, where the data type changes depending on how it’s used, you can overload it. This will allow you to create as many versions of SendMessage as needed. SLIDE TRANSISTION: Let’s take a look at overloading a little more closely. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: If you are upgrading an API that uses different signatures, overloading is the solution. SLIDE BUILDS: None SLIDE SCRIPT: Overloading is when you create two (or more) routines with the exact same name but with different parameter signatures. Here is an example of overloading the SendMessage API. Here we have two versions of SendMessage. Both have the same name. The only difference is that the last parameter’s type is different. In the first SendMessage, lParam is a String. But in the second SendMessage, lParam is an Integer. This is permissible in Visual Basic.NET because the compiler can easily tell which version your code is calling by the types of the parameters being passed in. SLIDE TRANSISTION: Passing a structure to an API call ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Passing a structure to an API may require marshalling attributes. SLIDE BUILDS: None SLIDE SCRIPT: In Visual Basic 6, when you created a structure (user-defined type), the individual members were always laid out in memory in the exact same order in which they were declared. In Visual Basic.NET, the common language runtime may reorganize the members in the way that is most efficient. APIs often require that the members of a structure be in a particular order. If the members are in a different order, the API may not work or may even crash your program. To ensure that the layout of a structure in memory is exactly the same as declared, you can use marshalling attributes. A marshalling attribute is an attribute that you add to a structure that provides additional information for how to handle that particular structure. Marshalling attributes are part of the System.Runtime.InteropServices namespace. The StructLayout attribute defines three different ways to lay out a structure: Automatic means that the common language runtime is free to reorder the members of the structure for efficiency. Sequential means that the members of the structure are to be laid out in unmanaged memory in the same order in which they are declared. Explicit gives you even more control. Using FieldOffsetAttribute, you can specify exactly were each member should go. SLIDE TRANSISTION: Do I still need the Win32 API? ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The .NET Framework comes with a lot of built-in functionality. Many of the API calls required in Visual Basic 6 many no longer be needed in Visual Basic.NET. SLIDE BUILDS: None SLIDE SCRIPT: When upgrading Win32 API calls, you may want to ask yourself if those particular APIs are really needed anymore. Visual Basic.NET has full access to the .NET Framework and the .NET Framework is a very feature-rich environment. Many of the APIs that were required to get around the limitations of Visual Basic 6 may no longer be required. SLIDE TRANSISTION: For example… ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Unlike Visual Basic 6, there is no longer a need to use the Win32 API to set the maximum length of a combo box in Visual Basic.NET. SLIDE BUILDS: None SLIDE SCRIPT: In Visual Basic 6.0, if you wanted to set the maximum length of text the user is allowed to type into a ComboBox, you would use the SendMessage API, passing in the handle of the combo box, the CB_LIMITTEXT constant and the number of characters as the limit. In Visual Basic.NET, the ComboBox now has a MaxLength property: ComboBox1.MaxLength = 20 No Win32 API is required. SLIDE TRANSISTION: Getting the create date of a file ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Visual Basic 6 provided no built-in way to get a file’s creation date time stamp. You either had to use an external library or ActiveX component, or use the Win32 API. With Visual Basic.NET, this function is built into the Framework. SLIDE BUILDS: None SLIDE SCRIPT: In Visual Basic 6.0, to get the date and time stamp of when a file was created, you couldn’t use Visual Basic’s FileDateTime function because this returned the time stamp of when the file was last modified, not the create date. You either had to rely on an external library or control, or the Win32 API. But using the Win32 API was quite complicated. First, you had to populate a WIN32_FIND_DATA structure by calling the FindFirstFile API function. Then you would call the FileTimeToSystemTime API to convert the file’s time to the local PC’s system time. But that required that you know what time zone you were in, in which case you had to call the GetTimeZoneInformation API. Once you knew the right time zone, you then call the SystemTimeToTzSpecificLocalTime API and then convert that to Visual Basic 6’s Date data type using the DateSerial and TimeSerial functions. But before you finish, you had to remember to call FindClose to free up the memory allocated by the call to FindFirstFile. In Visual Basic.NET, you simply call the GetCreationTime method of System.IO.File: System.IO.File.GetCreationTime(“C:\\Boot.ini”) SLIDE TRANSISTION: Min and Max sizes of a form ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Visual Basic 6 provided no built-in way to set a form’s minimum and maximum size. Again, either you could rely on a third-party control or the Win32 API. In Visual Basic.NET, these are now the properties of the form. SLIDE BUILDS: None SLIDE SCRIPT: In Visual Basic 6.0, there was no easy way to set the minimum or maximum size of a form. You had a few options. The first was to use the Form_Resize event. The user would be allowed change the form to any size they wanted, and in the Resize event you would resize the form back to what you wanted. The problem with this is that it was sloppy, and made the form look choppy on the screen. A more professional solution was to buy a third-party control or use the Win32 API. But again, writing the API was quite complicated. It required using the GetClientRect, DrawEdge, SetWindowLong, CallWindowProc and CopyMemory APIs. In Visual Basic.NET, all Windows Forms have MinimumSize and MaximumSize properties. You can set them directly from the Properties Window. SLIDE TRANSISTION: But, of course, Visual Basic.NET doesn’t include everything. There will still be times when you have to rely on the Win32 API. One such example is displaying the Browse for Folder dialog… ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: This demonstration shows how to upgrade Win32 API calls. SLIDE BUILDS: SLIDE SCRIPT: For the next demonstration we’ll take a look at how to upgrade Win32 API calls. We’ll use the Upgrade Wizard, but the Upgrade Wizard only performs part of the conversion. Part of the upgrade process is manual, and we’ll walk through that step by step. SLIDE TRANSITION: Next Agenda Item ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The next agenda item is printing in Visual Basic.NET SLIDE BUILDS: None SLIDE SCRIPT: Printing in Visual Basic.NET has changed significantly from it’s predecessor VB 6. SLIDE TRANSISTION: Printing in VB 6 ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: A brief review of printing in Visual Basic 6. SLIDE BUILDS: None SLIDE SCRIPT: In Visual Basic 6.0, printing was performed via the Printer object. The Printer object was static. That is, you didn’t need to create an instance of it. It represented the default system printer. The Printer object had many familiar properties and methods, such as Copies, Orientation, ColorMode, DeviceName, Port, etc. To print text, you would use the Print method. A simple “Hello world” program only required one line of code. Printing a graphic image was also fairly simple. You would create a Picture object and pass that into the PaintPicture method along with the location on the printed page as a set of x, y coordinates, the desired height and width of the picture, along with several other optional parameters. Another part of printing in Visual Basic 6 was the Printers collection. This contained a list of all available printers on the user’s system. This list is the same list displayed in the Windows Print dialog box. Finally, Visual Basic 6 came with a control to help facilitate printing. This was the CommonDialog control. By calling the ShowPrinter method, Visual Basic would display the standard Windows Printer dialog box. SLIDE TRANSISTION: Printing the .NET Way ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: An introduction to printing in Visual Basic.NET begins with the PrintDocument object. SLIDE BUILDS: None SLIDE SCRIPT: Printing in Visual Basic.NET is quite a bit different. The Printer object, the Printers collection and the CommonDialog.ShowPrinter method are no longer present. That doesn’t mean that functionality no longer exists. It does. In fact, Visual Basic.NET provides some very feature-rich printing capabilities. However, the objects and the way they are used are not the same. Admittedly, some things in Visual Basic.NET are more complicated. For example, you cannot write a 1-line “print ‘Hello world’” program in Visual Basic.NET. It now requires about 8 lines. However, other things are much simpler, as we will see. Plus, Visual Basic.NET does give you more power than Visual Basic 6. The main object you will use to print in Visual Basic.NET is called the PrintDocument object. The PrintDocument is exactly what its name implies. It’s an object that represents the document you want to print. To begin the printing process, you call its Print method. This causes the PrintPage event to fire. You then use the PrintPage event procedure to print each page of your document, one page at a time. One of the arguments that is passed into the PrintPage event procedure is the Graphics object. You use the Graphics object to do your printing. Specifically, to print a line of text to the printer, you call the DrawString method of the Graphics object. This is somewhat similar to Visual Basic 6’s Printer.Print method. To print a picture, you call the DrawImage method of the Graphics object. This is roughly equivalent to Visual Basic 6’s Printer.PaintPicture method. SLIDE TRANSISTION: Setting page properties for printed output. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: The PageSettings object contains the settings that apply to a single, printed page. SLIDE BUILDS: None SLIDE SCRIPT: The PageSettings object is used to specify settings that modify the way a page will be printed, such as Landscape, Margins, and PrinterResolution. You tell the PrintDocument object which settings you want by simply passing a populated PageSettings object to PrintDocument.DefaultPageSettings. SLIDE TRANSISTION: Design time support for printing ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Visual Basic.NET has 5 new controls for printing. SLIDE BUILDS: None SLIDE SCRIPT: Visual Basic.NET introduces 5 new controls for printing. The PrintDocument control is exactly the same as the PrintDocument object we’ve been talking about. The only difference is that this is a control, so it’s in the toolbox and you can drag it and drop it on your form. So basically, you have two choices when it comes to PrintDocument. If you prefer a more visual, design-time experience, use the PrintDocument control. If you prefer to write the code, you can do that, too. The PrintDialog control displays the standard Windows Print dialog. This is very much equivalent to Visual Basic 6’s CommonDialog.ShowPrinter. The PageSetupDialog is completely new to Visual Basic. This displays a dialog box that allows users to manipulate page settings, including margins and paper orientation. You use this dialog in tandem with the PageSettings object we discussed in the last slide. The PrintPreviewDialog is also completely new to Visual Basic. It displays a ready-made dialog box that allows users to see what their document is going to look like without printing it. The PrintPreviewControl is the raw "preview" part of print previewing, without the dialog box or buttons. If you want to create a custom print preview dialog, this is the control you want to use. SLIDE TRANSISTION: OK, now that we’ve covered some theory, let’s take a look at printing in action. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Demonstration #5 covers printing in Visual Basic.NET SLIDE BUILDS: SLIDE SCRIPT: Our final demonstration has two parts. The first is a simple ‘Hello World’ program to demonstrate the very basics of printing in Visual Basic.NET. The second part is a little more involved. This demonstrates how to print graphics from Visual Basic.NET and how to use the new print controls. SLIDE TRANSITION: Session Summary ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Session Summary SLIDE BUILDS: None SLIDE SCRIPT: In sum Visual Basic.NET offers a wide range of new features as well as providing a fully object oriented language. It is closely integrated with the .NET Framework and can access all of it’s inherent functionality. The Upgrade Wizard while covering approximately 95% of the upgrade scenarios may need some manual help from time to time. Finally when you need to you can easily interop with your existing VB 6 components. SLIDE TRANSITION: For more Information ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: For more information you can visit the following web sites. SLIDE BUILDS: None SLIDE SCRIPT: More information can be found on the following web sites. SLIDE TRANSITION: MSDN provides essential resources for developers. ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: MSDN SLIDE BUILDS: None SLIDE SCRIPT: MSDN is the essential resource for developers. It contains subscriptions, such as MSDN online and MSDN flash (as the MSDN web is becoming the central portal for developers). It has membership programs which are coordinated online as well as user groups. There are print publications as well as a variety of training and events - at local, national, and international levels. SLIDE TRANSITION: ADDITIONAL INFORMATION FOR PRESENTER:
  • Key Message: How-To Resouces SLIDE BUILDS: none SLIDE SCRIPT: How-Tos are designed to provide developers with simple, step-by-step procedures for accomplishing common development tasks. How-Tos cover a wide range of ability levels, from getting started with XML to working with embedded databases. We'll be adding many more How-Tos in the coming months, so check back often to get the latest insights on working with Microsoft products and technologies. SLIDE TRANSITION: ADDITIONAL INFORMATION:
  • Key Message: MSDN Webcasts SLIDE BUILDS: none SLIDE SCRIPT: Participate in an interactive, synchronous, live online event discussing the hottest topics from Microsoft. Experiences available now are open and free for the general public. Find out more about the MSDN Webcast program , which takes place on Tuesdays. Please note that registration closes 2 hours prior to the event start time. SLIDE TRANSITION: ADDITIONAL INFORMATION:
  • KEY MESSAGE: MSDN Subscriptions SLIDE BUILDS: None SLIDE SCRIPT: With Visual Studio .NET we continue to have the Professional and Enterprise versions plus we are adding the Enterprise Architect version that provides the modeling and design tools for systematic design of applications. And to provide even broader coverage for developers, this month we introduced a new product line for MSDN, and announced that every version of Visual Studio .NET will have a corresponding version of MSDN, so developers will have the choice of whether to buy Visual Studio .NET – the packaged product, or MSDN – the subscription service. If asked for pricing, here are the pricing offerings for the MSDN Subscriptions: MSDN Universal $2799 new/ $2299 renewal/upgrade MSDN Enterprise $2199 new/$1599 renewal/upgrade MSDN Professional $1199 new/$899 renewal/upgrade MSDN OS $699 new/$499 renewal MSDN Library $199 new/$99 renewal
  • KEY MESSAGE: Educate developers on where to go, how to be a part of MSDN. SLIDE BUILDS: None SLIDE SCRIPT: There is one place you should go to start: MSDN.MICROSOFT.COM There is one communication you should subscribe to: MSDN Flash. Twice monthly listserve for the developer community - focuses on news, information, resources and events Look for MSDN branded events - feature SLIDE TRANSITION: ADDITIONAL INFORMATION FOR PRESENTER:
  • Key Message: MS Press SLIDE BUILDS: none SLIDE SCRIPT: Through the use of Microsoft® Visual Studio® .NET and the .NET Framework, Microsoft provides developers with a full set of development tools to quickly and easily create state-of-the-art applications and XML Web services. Start building the leading-edge development skills you need to increase your productivity and enhance your career with selected Microsoft Press® books. Also, the Microsoft Enterprise Learning Library (MELL) Developer Edition is a must-have for corporate programmers who need effective training and reference resources in electronic format in order to build applications and systems using Microsoft languages and technologies. Current contents include 15 online training courses and 31 electronic books. Available via Microsoft’s volume licensing programs. SLIDE TRANSITION: ADDITIONAL INFORMATION:
  • KEY MESSAGE: The MCSD program SLIDE BUILDS: none SLIDE SCRIPT: The Microsoft Certified Solution Developer (MCSD) credential is the premium certification for professionals who design and develop custom business solutions with Microsoft development tools, technologies, and platforms. There is a new track which includes certification exams that test users’ ability to build Web-based, distributed, and commerce applications by using Microsoft’s products, such as Microsoft SQL™ Server, Microsoft Visual Studio, and Microsoft Component Services. For more information about the MCSD certification, please visit: www.microsoft.com/mcp. SLIDE TRANSITION: ADDITIONAL INFORMATION FOR PRESENTER:
  • KEY MESSAGE: Microsoft Training & Certification SLIDE BUILDS: none SLIDE SCRIPT: Microsoft Training & Certification develops the courseware called Microsoft Official Curriculum (MOC), including MSDN Training courses. MOC offers comprehensive training courses for both IT professionals and developers who build, support, and implement solutions using Microsoft products and technologies. Please be sure to tell the audience that these training courses are related to the subject that was just covered in the slides, but they do not necessarily provide in-depth coverage of this exact subject as it may include other topics. Anyone interested in more information about the course(s) listed should visit the Microsoft Training & Certification Web site at www.microsoft.com/traincert and review the syllabus. All MOC courses are delivered by Microsoft’s premier training channel, Microsoft Certified Technical Education Centers and classes are taught by Microsoft Certified Trainers. SLIDE TRANSITION: ADDITIONAL INFORMATION FOR PRESENTER:

Best practices for upgrading vb 6.0 projects to vb.net Best practices for upgrading vb 6.0 projects to vb.net Presentation Transcript