views:

42

answers:

3

I have some VB.NET (which I don't normally deal with) code which must be converted to C# (which I normally do).

The code happens to be in a Windows Forms app. I notice a couple of places such as:

Public Sub New()
    ParentWindow = Me

where there is no ParentWindow variable defined, and it doesn't seem to be inherited here:

Public Class MainWindow
    Inherits System.Windows.Forms.Form

    Private Shared parentWindow As MainWindow
    '....

(Though note that there is a similar variable with a lower-case first letter.)

and this:

DocumentCount = 0;

where, again, there is no corresponding variable definition and a straight conversion to C# Windows Forms indicates that there is no such member in the parent class.

Am I missing an import somewhere, or is this a feature peculiar to VB.NET that doesn't translate directly to C#?

+3  A: 

If this is working it's likely that you have Option Explicit set to off. This is a feature of VB.Net that allows for variables to be used before they are declared. Try adding the following to the top of the file

Option Explicit On
JaredPar
I haven't programmed in VB.NET for awhile and couldn't remember if it was Option Explicit or Option Strict...
Jason Punyon
The original VB.NET code has "Option Explicit On" an "Option Strict On", but the variables have to be declared at some point, right? documentCount and parentWindow are defined, but no other occurences that start with upper-case characters.
Buggieboy
If I do a case-insensitive search for "documentcount", I get: 1.) Private Shared documentCount As Integer 2.) DocumentCount = 0 3.) Public Shared Function GetDocumentCount() As Integer 4.) Return documentCount 5.) documentCount += 1 6.) DocID = MainWindow.GetDocumentCount() + 1 Notice that the leading-upper-case "DocumentCount" variable appears only once in any .vb file.
Buggieboy
A: 

VB is case insensitive. So parentWindow and ParentWindow may very well refer to the same variable. Usually the IDE fixes the case for you though...

Meta-Knight
Wait... I got downvoted for this yet I gave the same answer as the accepted one??
Meta-Knight
+1  A: 

VB is case insensitive, so it's actually assigning to parentWindow and documentCount.

(Edited in response to other comment)

SLaks
Got it.A good thing to know when converting to a "C"-style language. It would have been nice if the orignal programmer had chosen a style and stuck to it.
Buggieboy