In 1999 Francesco Balena wrote Programming Microsoft Visual Basic 6 (Microsoft Press), which rapidly became one of the best-selling books on Visual Basic. It has been translated to Italian, Spanish, Japanese, Korean, Chinese (simplied, China), Chinese (traditional, Taiwan), and local English-version for India and – unbelievably – still sells more than many .NET books.

Unlike most tutorial books that just scratch the Visual Basic surface, in its 1200 pages Programming Microsoft Visual Basic 6 covers virtually every single facet of VB6 programming, such as advanced database programming, Windows API calls, COM components, user controls, graphics, and more.You can read reviews on Amazon here.

.

Seven years later, Francesco is the lead programmer in VB Migration Partner team. Because the book covers such a broad range of techniques, testing the tool against its code samples was a natural decision.

Not surprisingly, not all the samples can convert correctly. For example, we didn’t try samples from chapters 19 (DHTML applications) and 20 (IIS Applications), because VB Migration Partner doesn’t support these two features. (If you have a program that uses WebClass components, we strongly recommend that you rewrite it from scratch as an ASP.NET.) Of the remaining 101 samples, only one dozen exhibit problems of any sort, as we clearly explain in the list that follows.

Download the full VB6 source code

Rectangl:

Demos the Click and Change events.

Digital Clock:

Uses a Timer control and the Print method to display current time. Requires an InsertStatement pragma to account for extra leading whitespace in Print output.

Palettes:

Uses LoadPicture, API methods, Line statement with BF option.

RubberBand:

Works correctly, except rubber-banding doesn’t work because lack of support for DrawMode property.

WordWrap:

Uses the TextWidth method to wrap long text lines.

Hyperlinks:

Works as expected, except cursors assigned via MouseIcon property aren’t transparent.

ImgPreview:

Uses DriveListBox, DirListBox, and FileListBox controls, and the PaintPicture method to create a simple image viewer.

MultiSelectListBox:

Shows how you can programmatically select or deselect items in a ListBox controls with or without checkboxes, and how you can prevent the end user from selecting certain items.

PaintPic:

Uses PaintPicture method to create several fading effects.

PickClor:

Demonstrates scrollbars, including “upside-down” vertical scrollbars whose “max” position is at the top.

PoorManTables:

Two listbox controls that are scrolled in sync.

ScrollFrm:

A scrollable form. Requires an InsertStatement pragma to work around a refresh issue of the Data control.

TwinListboxes:

Two listbox controls with four buttons to move items from one listbox to the other.

Validate:

Uses the Validate event to validate fields.

Routines:

An assortment of reusable routines.

Clipbord:

Uses the Clipboard object to copy and paste content of TextBox, RichTextBox, and PictureBox controls. Demonstrates that the Menu_Click event fires correctly for dropdown menus. Everything works as expected, except the RichTextBox controls doesn’t support pasting images.

Routines:

An assortment of routines.

Shell:

Uses the AppActivate and Shell methods. Original code was edited to solve an issue with the SendKeys method.

Person:

A simple object hierarchy.

SMatrix:

Demo of two classes that use default properties to implement sparse matrix and triangular sparse matrix objects.

Terminat:

Demonstrates how Class_Terminate event handlers are translated correctly to VB.NET. An AutoDispose pragma was added to force disposable of objects stored in local variables. Note: must be run with Administrator privileges disabled on Microsoft Vista, else the GetTempFileName API methods throws a runtime exception.

Shapes3:

A simple drawing program that demonstrates polymorphism through interfaces, graphic shapes, and graphical buttons. Original code had to be modified; we used a #IF VBC_VER condition, so that old and new code can coexist in the original VB6 project. A reference to Color value was wrapped in FromOleColor6 methods (defined in the VBMigrationPartner_Support module).

Places:

Demonstrates that VB Migration Partner can correctly migrate enumerable collection classes and graphic statements.

Invoice:

A hierarchy of eight classes. Demonstrates that VB Migration Partner correctly migrates default members and enumerable collection classes. Uses a project-level AutoNew pragma to implement lazy instantiation semantics of As New variables.

CTextBxN:

Two classes that wrap TextBox controls and trap their events, to implement numeric fields and calculated fields, respectively. The sample is heavily based on Variant variables and default members in late-bound mode. It uses one pragma to force usage of VB6Array and one pragma to define the VB6Empty constant.

CFileOp:

Demonstrates a class that raises event, including events whose name is a reserved keyword (“Error”), and Variant arguments.

ADO Data:

Demonstrates ADO binding and the ADO Data control.

DataEnv:

Demonstrates a DataEnvironment object bound to individual fields and to a DataGrid control.

DataFrmt:

Demonstrates that VB Migration Partner fully supports databinding with DataFormat objects, including date/time formats and Format events. It requires the manual addition of the FromOleColor6 method (defined in VBMigrationPartner_Support module) to avoid runtime errors when assigning the ForeColor property in late-bound mode.

Hierarch:

Uses a hierarchical DataEnvironment bound to a MS FlexGrid control. The sample is migrated with zero compilation errors, but fails at runtime, because VB Migration Partner does not currently support groupings and relations in DataEnvironment objects.

MastDet:

This project was generated by VB6 Data Form wizard and demonstrates a master-detail view of the Orders and OrderDetails tables in Northwind, using several bound fields and a DataGrid.

SQL:

Demonstrates that VB Migration Partner generates the wrapper for a COM library (Microsoft OLE DB Service Component 1.0 Type Library, in this specific case). Requires a ReplaceStatement pragma to work around a problem with default members.

AutoDrop:

Uses automatic OLE drag-and-drop functionality of several VB6 controls. Everything works as in VB6, except you can’t drop images or OLE objects onto a RichTextBox control.

DataDrvn:

Demonstrates exploration of fields of an ADO Recordset, dynamic control creation by means of Controls.Add method, and use of the VBControlExtender object to trap the Validate event. Requires an InsertStatement pragma to work around a problem with ADO Data control’s Refresh method.

DynCtrls:

Demonstrates dynamic control creation by means of Controls.Add method and MS Windowless controls.

Login:

A simple application that displays a login form.

ManDrop:

Demonstrates manual OLE drag-and-drop functionality of several VB6 controls. All features work correctly except drag-and-drop of custom objects, which VB Migration Partner doesn’t support.

MDINotep:

A Notepad-like application with MDI user interface that demonstrates menus and menu shortcuts, the Click event of dropdown menus, the menu’s WindowList property, and window tiling and arranging.

MDInterf:

A project group that demonstrates polymorphism through late binding, menus and menu shortcuts, toolbar, cut-and-paste operations, the Print and Print Setup common dialog (read more details in the original README.TXT for VB6 developers).

ObjView:

Demonstrates that events from controls can be trapped in different forms.

ReuseFrm:

Shows how to use forms as reusable classes; uses control arrays to create controls at runtime.

TxtBrows:

A simple text file browser.

DirBrow:

A simple directory tree browser that shows the TreeView control in action.

BrowMdb:

A browser for MDB files. Demonstrates the TreeView and database exploration with the DAO object model. Uses the UseByval pragma to work around a different behavior of VB6 and VB.NET related to how enumerated values are passed to Boolean parameters.

BrowseDB:

A simple browser for any ADO database. Demonstrates the TreeView and database exploration with the ADO object model. The VB.NET version works like the original code, except that the Node.Sorted property works better in VB.NET: the neat result is that nodes are sorted in VB.NET and unsorted in VB6. Requires that an argument in FieldTypeDesc method be declared as ByVal rather than ByRef, to work around the way VB.NET propagates values back to the caller.

DragDrop:

Demonstrates OLE drag-and-drop between TreeView controls.

ImgCombo:

Demonstrates the ImageCombo control and the FileSystemObject library. Notice that the migrated VB.NET application doesn’t rely on the FileSystemObject (COM) library: instead, it uses the VB6FileSystemObject included in VB Migration Partner’s support library.

ListDB:

Demonstrates using ADO objects to fill a ListView control; users can sort on any field by clicking on the ListView’s column headers.

ParseTV:

Demonstrates using a TreeView and all the properties of the Node object; copies a “text image” of the control’s current state into the Clipboard.

Printer:

A demo all the properties and methods of the Printer object. The VB.NET application produces exactly the same output as the original application, except that landscape printing doesn’t work.

Slider:

A demo of all the properties and methods of the Slider common control and the Line method. The VB.NET code works exactly like the original VB6 application, except the SelectRange method of the Slider control isn’t supported.

StatusBar:

Tests several programming techniques related to the StatusBar control, including hosting other controls on its panels, animated icons, creating new panels at runtime, panels with different styles, and changing the state of lock keys by double-clicking on the corresponding panel.

Animatio:

Tests all the properties and methods of the Animation common control.

Coolbar:

A demo of several features of the Coolbar control, including hosting a Toobar control. The code migrates correctly and the Toolbar is fully functional, but VB Migration Partner doesn’t support the Coolbar control and therefore replaces it with a VB6Placeholder; as expected, trying to add a new band results in a NullReference exception.

Coolbar2:

Demonstrates several features of the Coolbar control and the TransTBWrapper (a VB6 User control Microsoft released in source code to improve the Coolbar control’s functioning). The code migrates correctly and the Toolbar is fully functional, but the Coolbar control is replaced by a VB6Placeholder; as expected, trying to add a new band results in a NullReference exception.

DTPicker:

Tests several features of the DTPicker, including callback fields and key trapping inside callback fields. Requires one WriteProperty pragma for each DTPicker control, to work around a known issue with the control’s Format property. VB.NET code works like the original one, except VB Migration Partner doesn’t support callback fields and marks as obsolete the three events related to them (Format, FormatSize, and CallbackKeyDown).

FlatScrB:

Demonstrates several features of the FlatScrollBar control. The migrated VB.NET code works like the original application, except that scrollbar arrows can’t be disabled. A noteworthy detail: the LargeChange property is ignored, to correctly mimic VB6’s behavior.

MonthView:

Tests several features of the MonthView control. The converted VB.NET code works like the original application, except drag-and-drop and a few properties aren’t supported. A minor issue: the GetDayBold event doesn’t fire when a multi-month calendar is scrolled but the selected date remains into view.

UpDown:

Demonstrates several features of the UpDown control, including the ability to change the buddy control at runtime. Requires a WriteProperty pragma to work around a known issue with the UpDown’s BuddyControl property.

ComDlg:

Demonstrates several features of the CommonDialog control, including multi-selection File Open, and the RichTextBox control.

MaskEdit:

Demonstrates several features of the MaskEdBox control. The migrated VB.NET code works like the original application, except that data formats aren’t fully supported; occasional unexpected exceptions may occur, too.

RTFBox:

Demonstrates several features of the RichTextBox control, in an mini-wp application that uses also the Coolbar and the TransTBWrapper user control. Migrated application has no compilation errors, but the Coolbar control isn’t functional.

SSTab:

Demonstrates several features of the SSTab control, including adding a new tab at runtime, as well as the Validate event of fields on the SSTab control.

SysInfo:

Demonstrates several features of the SysInfo, including trapping system events.

ADOWorkb:

Allows you to test all the properties, methods, and events of ADO objects. Uses the SSTab and DataGrid controls intensively. Requires a ReplaceStatement pragma to work around a known issue with default methods of COM objects, when the method is accessed in late-bound mode.

ADOX:

A simple explorer for the hierarchical structure of ADO-compatible databases.

Asynch:

A demonstration of asynchronous ADO features. The code migrates without any compilation error, but the VB.NET code doesn’t work as intended because VB Migration Partner does currently support groupings and relations in DataEnvironment objects.

BatchUpd:

Allows you to test optimistic lock and batch update features in ADO.

StandAlo:

A demonstration of disconnected ADO recordsets and the DataGrid control.

FlexGrid:

A demonstration of several features of the MS FlexGrid control, bound to a hierarchical DataEnvironment object. The application migrates without any compilation error but no data hierarchy is displayed, because VB Migration Partner does currently support groupings and relations in DataEnvironment objects.

DataRep:

A demonstration of several features of the DataReport designer. The application generates 11 compilation errors, all caused by VB Migration Partner’s lack of support for the DataReport designer).

DataGrid:

The VB6 code has been modified to use the ToStdDataFormat6 method, defined in VBMigrationPartner_Support module. The application migrates without any compilation error, but throws ADO-related errors caused by the .NET wrapper created by AxImp.

DataComb:

Tests several features of the DataList and DataCombo controls, and the ADO Data control.

Benchmrk:

A project group that demonstrates relative speed of accesses to COM object in ActiveX DLL and ActiveX EXE files, created using New or the CreateObject method.

Callback:

Two projects that demonstrate calling an ActiveX EXE server object. VB Migration Partner converts the client application into a VB.NET project that correctly references the ActiveX EXE object through COM Interop.

CFileOp:

A project group with a Standard EXE project that uses a COM object located in an ActiveX DLL project.

FirstCom:

Same as Invoice sample in chapter 7, but implemented as a COM component.

Global:

A project group that implements and uses GlobalMultiUse COM components.

Login:

Similar to Login sample in chapter 9, but implemented as a project group with a Standard EXE project that uses an object in an ActiveX DLL project.

LogSvr:

A project group contains an ActiveX EXE and an ActiveX DLL project. The former uses the latter for logging purposes, and calls the CreateObject method on a SingleUse class to create a multi-threaded application. Requires two AutoNew pragmas to ensure that objects are instantiated when referenced. The code migrates and works correctly, except that this kind of multi-threading isn’t supported by the .NET Framework, therefore the VB.NET isn’t multithreaded.

MultiThr:

An ActiveX EXE project that creates a multi-threaded application by instanting a SingleUse class by means of CreateObject method. Requires an AutoNew pragma to ensure that objects are instantiated when referenced. The code migrates and works correctly, except that this kind of multi-threading isn’t supported by the .NET Framework, therefore the VB.NET isn’t multithreaded.

Persist:

A project group with an ActiveX DLL project that defines a persistable class. The code migrates correctly and behaves as expected. However, persisting to file doesn’t work correctly, because the FileGet6 method in VB Migration Partner’s current version can’t read uninitialized arrays.

RemotSvr:

Demonstration of remote communication through DCOM. This project can’t work after the migration because .NET doesn’t support Distributed COM.

Satellit:

A project group that demonstrates how to use satellite DLLs to store strings and images related to different locales. This sample is especially interesting because it shows that VB Migration Partner converts concrete classes that define an interface for other classes to implement, and that the CreateObject method works correctly with classes even after they have been migrated to .NET. Requires an AutoNew pragma to ensure that an object is instantiated when first referenced.

SpellChk:

An application that uses the Microsoft Word object model to provide spell checking functionality. VB Migration Partner correctly creates a .NET wrapper around the Word type library. A minor issue: when the application ends, the Word main window appears. (This problem is caused by COM Interop.)

Address:

A user control that maps a business object to its constituent fields.

Clock:

A simple user control that displays current time.

Customer:

A user control that uses the DataBindings collection to bind its fields to multiple columns in a data source. Requires an #IF VBC_VER section to manually assign data bindings, because current version of VB Migration Partner can’t decode serialized DataBindings properties.

DataRep:

A simple user control used together with the DataRepeater control to display a record in Biblio database. Migrated project doesn’t work, because current version of VB Migration Partner doesn’t support the DataRepeater control.

OptButn:

A radiobutton-like user control that demonstrates user controls that expose a Value Boolean property marked as OLE_OPTEXCLUSIVE. A bug prevents PictureBox containing metafiles from being displayed correctly at design time. The image displays correctly at runtime, though.

Resize:

A simple user control that resizes when the parent form resizes, so that it always takes the entire form’s surface. Requires a series of InsertStatement pragmas to account for the fact that the ReadProperties event isn’t fired under VB.NET.

ScrollPic:

A user control that combines a PictureBox with two ScrollBar controls to create a scrollable PictureBox.

Stretch:

A user control that moves and resizes its constituent controls when it is resized. Migrated VB.NET project doesn’t work correctly.

SuperLst:

A user control that expands on the ListBox control to support columns and advanced databinding.

SuperTB:

A user control that expands on the TextBox control to support built-in caption and formatting capabilities. We added a WriteProperty pragma to manually set the Multiline to True, else the textbox’s height can’t be modified.

SuperTim:

A user control that expands on the Timer control.

VTableBnd:

A user control that demonstrates that you can speed up your code by accessing an ActiveX through secondary interfaces and by receiving events through a secondary interface. The migrated project works correctly, even though there is no difference in timing under VB.NET.

ArrayDat:

Tests data source classes, that is, classes whose DataSourceBehavior property is set to 1-vbDataSource.

BindCol:

Demonstrates binding to the BindingCollection object, including support for custom formatting with the StdDataFormat object.

Complex:

A user control with DataBindingBehavior property set to 1-vbSimpleBound.

DatObjWz:

Tests classes and user control generated by the Visual Basic Object Data Wizard. Code migrates correctly but a NullReference exception is thrown at runtime. (VB Migration Partner doesn’t support applications generated by the Object Data Wizard.)

MyData:

A project group that defines custom Data control created using a User control whose DataSourceBehavior property is set to 1-vbDataSource.

OleDbPro:

An OLEDB Simple Provider. The converted VB.NET application doesn’t work, because VB Migration Partner doesn’t support OLEDB Simple Provider applications.

Simple:

Demonstates the BindingCollection object used with data bound classes, e.g. classes whose DataBindingBehavior property is set to 1-vbSimpleBound.

TextFile:

Demonstates data bound classes, e.g. classes whose DataBindingBehavior property is set to 1-vbSimpleBound. A noteworthy detail: if multiple forms are bound to the same instance of the data source, changing one field on either form changes the same on the other form, and pressing Next on either form changes the current record in the other form as well, as in VB6.

Samples for chapter 19 (DHTML Applications) and chapter 20 (IIS Applications) are omitted, because VB Migration Partner supports neither the DHTML Page designer nor WebClass components.

Callback:

Uses the SetTimer API function and a callback method through which the application is notified every N milliseconds.

EnumWindow:

Uses the EnumWindows, EnumChildWindows, GetWindowText and GetClassName API functions to display information on all the open windows on the desktop. It demonstrates that callback methods are fully supported.

MsgHook:

It’s a project group, with a demo client that uses an ActiveX DLL that allows safe implementation of window subclassing. It requires a few pragmas to keep the delegate passed to the SetWindowLong API method alive between garbage collections. The VB.NET application works exactly like the original VB6 code, except that .NET menus don’t send the WM_MENUSELECT message when the end user selects them.

Registry:

Uses Windows API functions to retrieve data from the Registry, including information on all the COM classes and VB6 settings. It also shows how to create and delete registry keys and values. Three ArrayRank pragmas have been added to the original VB6 code.

SendMsg:

Uses SendMessage API function to implement additional features for TextBox, ListBox, and ListView controls. A few ReplaceStatement pragmas were added to work around issues caused by arrays with non-zero LBound.

Subclass:

Demonstrates windows subclassing, using SetWindowLong and CallWindowProc API functions. While VB Migration Partner does support window subclassing, this sample has been decorated with several pragmas to use the VB6WindowSubclasser class, which offers safer and more robust subclassing.

System:

Uses an assortement of Windows API methods to display system information, clip the area where the mouse can move, affect lock keys, and trap keys pressed when the application doesn’t have the input focus. Uses a UseSystemString pragma to fix a problem in a UDT being passed to a Windows API.

VBRegFun:

Demonstrates VB6 registry functions (i.e. SaveSetting, GetSetting, DeleteSetting).