| The VB.NET Upgrade Wizard | ||||||
| Working Code At Last -- Sort Of | ||||||
|
At this point, the program will now run (more or less) successfully. But there are still a few surprises. Some of the things that still don't look quite right include:
Some of these things can be fixed without recoding the entire application, and some can't. Most relate to the mixing of GDI+ with other controls. Looks like Cornell and Morrison's warning about "subtle hazards" is right on target. |
||||||
A quick and simple way to erase the win lines when a new game starts is to add an Invalidate() statement in the InitPlayGround subroutine. This function tells Windows that the contents of a window are no longer valid so that it will need to be redrawn. The second problem can be fixed with a bit more coding. If you scan the converted source code, you see this interesting comment added by the conversion wizard just before each section of code where the problem warning window can be displayed. UPGRADE_WARNING: Event optOPlayer.CheckedChanged may fire when form is intialized. Click for more:
'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup2075"' How convenient! Clicking the link gives you an interesting page that immediately plunges you into a page that assumes you completely understand how to use object inheritance in VB.NET. The page includes the helpful hint: What to do next And this example code is also included: For many VB 6 programmers just learning VB.NET, this might be like instructions for climbing Mount Everest that start with, "Making the final assault ... " Wait a sec! We have to get close to the summit first! In brief (very brief, in fact, way too brief), DefInstance is a form object property derived from the base form. You can see it declared in the "Upgrade Support" Region that was automatically created by the conversion wizard. You can add another property - the hint suggests that you call it IsInitializing - with the new Property syntax for VB.NET. Property Set, Property Let and Property Get are not supported in VB.NET. (What! More new, incompatible stuff? Yes, yes, and yes again!) Here's how you can code a new property for the main form, frmTicTacToe. The Get and Set here are entirely different from the ones in VB 6. Once this property is available in frmTicTacToe, you can add this to the initialization code: frmTicTacToe.DefInstance.IsInitializing = False and this to the two problem subroutines (only the first is shown): In our final, VB.NET only version, we do away with this kind of confusing code adjustments entirely. This is another reason why you might want to consider just starting over to convert to VB.NET. This still doesn't solve the problem of the GDI+ graphics used for the win lines not refreshing or painting correctly. For this, we'll have to wait for the next version of Tic Tac Toe that is created the "VB.NET" way! The two main goals of this article were to introduce you to VB.NET and the conversion wizard, but more importantly, to convince you that VB.NET is a whole 'nother world. As Dorothy might have said if the tornado had taken her to VB.NET instead of Oz, "Toto, we're not in Visual Basic anymore!" |
||||||

"Add an IsInitializing property to the form" ???
