Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
The VB.NET Upgrade Wizard
Conversion Problem Number Two
 Related Resources
• The VB 6 Version:
TicTacToe

• A GDI+ Introduction for Visual Basic 6 Programmers
• A GDI+ Introduction for Visual Basic 6 Programmers
• Source for Upgraded .NET Version
 


Conversion Problem Number Two

The next problem to be overcome is a direct consequence of the another of the fundamental changes in the way VB.NET works. In the original VB 6 program, both arrays IOPos() and iXPos() are passed to the CheckWin subroutine since the processing was identical for each of them. Here are the original VB 6 statements:

iWin = CheckWin(iOPos())

and

iWin = CheckWin(iXPos())

These were converted to:

iWin = CheckWin(iOPos)

and

iWin = CheckWin(iXPos)

and both of these generate the error statement:

Value of type '2-dimensional array of Short' cannot be converted to '1-dimensional array of Short' because the array types have different numbers of dimensions.

It turns out that VB.NET has changed the concept of arrays a great deal. To understand why this is a problem, you have to understand that in VB.NET, everything is an object, including arrays.

Since VB.NET treats arrays as objects, you can simply reference them by name rather than using the parentheses required in VB 6. This accounts for the change in the language syntax above. The old VB 6 syntax identified the arrays as iOPos() and iXPos(). The new VB.NET just calls them iOPos and iXPos. The problem, however, is on the other end of the call - in the called function Checkwin.

This function has been converted from the VB 6 form:

Function CheckWin(ByRef iPos() As Integer) As Integer

to

Function CheckWin(ByRef iPos() As Short) As Short

So far, so good. The change from Integer to Short in the variable declarations shouldn't be a problem. But VB.NET insists that the array iPos is a one dimensional array ("an array of rank 1" in the documentation). VB 6 can figure out that iPos is a multidimensional array. VB.NET requires that you show this in the code.

The documentation does make this note about changes to array declarations in VB.NET:

The number of dimensions must be fixed. The following example declares a three-dimensional array:
Dim Point( , , ) As Double

This leads directly to the fix in the declaration of CheckWin

Function CheckWin(ByRef iPos(,) As Short) As Short

This change gets rid of both errors and at least allows the program to compile cleanly, but other errors, specifically the fact that we no longer have linwin components in our program, will still make the program to crash when you try to run it.

Next page > A 'Gotcha' For A Good Cause > Page 1, 2, 3, 4, 5, 6, 7, 8, 9

Explore Visual Basic

By Category

About.com Special Features

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.