Naming convensions for VB.NET that are different than VB 6 
Author Message
 Naming convensions for VB.NET that are different than VB 6

Naming convensions for VB.NET that are different than VB 6.

In VB6 you were able to work with a form by its name. If you named it Form1,
you could call methods using that name.

In VB.NET, you have to (at least, I am not aware of how to do it) declare a
variable, then instantiate the form with the variable. (I am aware you can
do this with vb6, but it is not the preferred way). To manipulate the form,
you use the variable, not the name of the form.

Having said that, I have a question to propose to the seasoned programmers
out there that practice good naming and programming practices: What naming
convention do you use for your form variables in VB.NET? If you have a form
named "frmCustomer" and you want to use the "frm" naming prefix for all your
form variables, then what exactly do you name the form variable,
"frmCustomer"? This wont work because that's the name of the form class. You
could put something on the end to make it differnt than the form class'
name, like "frmCustomer1", but that would be sloppy and random. Does anyone
use a good methodical way of naming these types of things in VB.NET?

Thanks!

--Aron, MCP, MCSD, MCT



Tue, 27 Jul 2004 01:46:40 GMT  
 Naming convensions for VB.NET that are different than VB 6
Aron -

Very good question.

I've searched long and hard for the answer to this myself, and the answer
seems to be that there is no answer.  Everybody does it differently.

As far as the way I do it - in VB6, I would call a form frmCustomer and the
variable friCustomer (as in form instance).  I'm still trying to figure out
what convention I'm going to use in VB.NET.  I've abandoned the three
character prefix as unworkable as there are now millions of different types
of objects and it seems pointless to think up a three character prefix for
all of them. In VB.NET I call a form CustomerForm.

This is one thing that has always bugged me about VB - the lack of standards
for program structure, variable naming conventions, etc.  The naming
conventions documents that Microsoft has produced are woefully inadequate.
If someone at Microsoft spent a few months putting together a definitive
document for naming conventions it would, in my opinion, make the world a
better place for those of us who don't care what convention we use, just as
long as (most) everyone else uses it.

- Rick


Quote:
> Naming convensions for VB.NET that are different than VB 6.

> In VB6 you were able to work with a form by its name. If you named it
Form1,
> you could call methods using that name.

> In VB.NET, you have to (at least, I am not aware of how to do it) declare
a
> variable, then instantiate the form with the variable. (I am aware you can
> do this with vb6, but it is not the preferred way). To manipulate the
form,
> you use the variable, not the name of the form.

> Having said that, I have a question to propose to the seasoned programmers
> out there that practice good naming and programming practices: What naming
> convention do you use for your form variables in VB.NET? If you have a
form
> named "frmCustomer" and you want to use the "frm" naming prefix for all
your
> form variables, then what exactly do you name the form variable,
> "frmCustomer"? This wont work because that's the name of the form class.
You
> could put something on the end to make it differnt than the form class'
> name, like "frmCustomer1", but that would be sloppy and random. Does
anyone
> use a good methodical way of naming these types of things in VB.NET?

> Thanks!

> --Aron, MCP, MCSD, MCT



Tue, 27 Jul 2004 02:38:41 GMT  
 Naming convensions for VB.NET that are different than VB 6

Quote:
> Naming convensions for VB.NET that are different than VB 6.

> In VB6 you were able to work with a form by its name. If you
> named it Form1, you could call methods using that name.

> In VB.NET, you have to (at least, I am not aware of how to do
> it) declare a variable, then instantiate the form with the
> variable. (I am aware you can do this with vb6, but it is not
> the preferred way). To manipulate the form, you use the
> variable, not the name of the form.

No, you didn't work with it's name. You worked with an automatically
generated, invisible and global variable that had the same name as the
form's class name. This lead to many confusion in the past if one wasn't
aware of this fact. The most common problem was that the program hasn't been
terminated correctly. The "solution" has often been the usage of the evil
End statement. The real reason was the mixture of using the global variable
and other created instances by using the new keyword. Additionally, the
global instance is defined "As New Anyform", that means it's instanciated
automatically.

Quote:
> Having said that, I have a question to propose to the seasoned
> programmers out there that practice good naming and programming
> practices: What naming convention do you use for your form
> variables in VB.NET? If you have a form named "frmCustomer" and
> you want to use the "frm" naming prefix for all your form
> variables, then what exactly do you name the form variable,
> "frmCustomer"? This wont work because that's the name of the
> form class. You could put something on the end to make it
> differnt than the form class' name, like "frmCustomer1", but
> that would be sloppy and random. Does anyone use a good
> methodical way of naming these types of things in VB.NET?

class name: CustomerForm
variable name: CustomerForm

You can use the same name. I use the suffix because it _is_ a Form. Which
Form? A "CustomerForm".

Armin



Tue, 27 Jul 2004 02:52:05 GMT  
 Naming convensions for VB.NET that are different than VB 6


Quote:
>  ...

> class name: CustomerForm
> variable name: CustomerForm

> You can use the same name. I use the suffix because it _is_ a Form. Which
> Form? A "CustomerForm".

> Armin

One of the benefits I get from using prefixes is that objects are list by
type in intellisense.


Tue, 27 Jul 2004 04:03:45 GMT  
 Naming convensions for VB.NET that are different than VB 6

Quote:
> > class name: CustomerForm
> > variable name: CustomerForm

> > You can use the same name. I use the suffix because it _is_ a
> > Form. Which Form? A "CustomerForm".

> One of the benefits I get from using prefixes is that objects
> are list by type in intellisense.

One of the benefits from using a suffix is that classes are listed
alphabetically. ;-) No, seriously, I really don't know which one is faster.
Another suggestion: One can create a Forms namespace only containing forms
and use Dim CustomerForm As Forms.Customer

Armin



Tue, 27 Jul 2004 05:01:19 GMT  
 Naming convensions for VB.NET that are different than VB 6
Hmmm... that's not a bad idea... well done.

Tim Overbay


Quote:

> > > class name: CustomerForm
> > > variable name: CustomerForm

> > > You can use the same name. I use the suffix because it _is_ a
> > > Form. Which Form? A "CustomerForm".

> > One of the benefits I get from using prefixes is that objects
> > are list by type in intellisense.

> One of the benefits from using a suffix is that classes are listed
> alphabetically. ;-) No, seriously, I really don't know which one is
faster.
> Another suggestion: One can create a Forms namespace only containing forms
> and use Dim CustomerForm As Forms.Customer

> Armin



Tue, 27 Jul 2004 06:37:00 GMT  
 Naming convensions for VB.NET that are different than VB 6
I just asked one of my fellow coding buddies and he said to do the following

class name: cls_frmCustomer
variable name: frmCustomer

Seems to make sense to me, since the cls_frmCustomer is really a class

--Bob

=============


Quote:
> Naming convensions for VB.NET that are different than VB 6.

> In VB6 you were able to work with a form by its name. If you named it
Form1,
> you could call methods using that name.

> In VB.NET, you have to (at least, I am not aware of how to do it) declare
a
> variable, then instantiate the form with the variable. (I am aware you can
> do this with vb6, but it is not the preferred way). To manipulate the
form,
> you use the variable, not the name of the form.

> Having said that, I have a question to propose to the seasoned programmers
> out there that practice good naming and programming practices: What naming
> convention do you use for your form variables in VB.NET? If you have a
form
> named "frmCustomer" and you want to use the "frm" naming prefix for all
your
> form variables, then what exactly do you name the form variable,
> "frmCustomer"? This wont work because that's the name of the form class.
You
> could put something on the end to make it differnt than the form class'
> name, like "frmCustomer1", but that would be sloppy and random. Does
anyone
> use a good methodical way of naming these types of things in VB.NET?

> Thanks!

> --Aron, MCP, MCSD, MCT



Tue, 27 Jul 2004 06:39:27 GMT  
 Naming convensions for VB.NET that are different than VB 6

Quote:
> class name: CustomerForm
> variable name: CustomerForm

> You can use the same name. I use the suffix because it _is_ a Form. Which
> Form? A "CustomerForm".

I like the "Form" suffix. It is consistent with the framework's "Attribute"
and "Exception" suffixes, and doesn't interfere with Intellisense.

--
Jonathan Allen



Tue, 27 Jul 2004 07:02:04 GMT  
 Naming convensions for VB.NET that are different than VB 6

Quote:
> class name: cls_frmCustomer

That is even worse than putting "C" in front of every class. You have to
type seven letters before intellisense can even begin to work.

--
Jonathan Allen

.Net Wish List Site: http://jonathan.cloverlink.com/


Quote:
> I just asked one of my fellow coding buddies and he said to do the
following

> class name: cls_frmCustomer
> variable name: frmCustomer

> Seems to make sense to me, since the cls_frmCustomer is really a class

> --Bob

> =============



Tue, 27 Jul 2004 07:06:03 GMT  
 Naming convensions for VB.NET that are different than VB 6
Aron,
In addition to the other suggestions. I use a Singleton Pattern. Which also
happens to basically be what MS does when it converts a VB6 project to
VB.NET ;-)

The reason I use a Singleton Pattern is its the tried & proven OOP approach.
See "Design Patterns - Elements of Reusable Object-Oriented Software" by GOF
(Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides) from
Addison-Wesley Professional Computing Series.

Making a form a 'Singleton', which may not be what you want, but should
give you ideas.

To make frmMain a 'Singleton' means that only one instance of the form will
exist, ever. Use something like:

Class frmMain
    Inherits System.Windows.Forms.Form

#Region " Singleton Pattern "

    Private Shared m_instance As frmMain

    Public Shared ReadOnly Property Instance() As frmMain
        Get
            If m_instance Is Nothing Then
                m_instance = New frmMain()
            End If
            Return m_instance
        End Get
    End Property

    Private Sub New()
        ' Ensure that no one else can create the class...
    End Sub

#End Region

End Class

Then where ever you want to refer to the main form.

    frmMain.Instance

Also depending on the desired effect, you will want to handle either the
Closing Event or the Closed event. Prevent closing in the Closing Event
(consider hiding) or Clear 'm_instance' in the closed event.

Hope this helps
Jay


Quote:
> Naming convensions for VB.NET that are different than VB 6.

> In VB6 you were able to work with a form by its name. If you named it
Form1,
> you could call methods using that name.

> In VB.NET, you have to (at least, I am not aware of how to do it) declare
a
> variable, then instantiate the form with the variable. (I am aware you can
> do this with vb6, but it is not the preferred way). To manipulate the
form,
> you use the variable, not the name of the form.

> Having said that, I have a question to propose to the seasoned programmers
> out there that practice good naming and programming practices: What naming
> convention do you use for your form variables in VB.NET? If you have a
form
> named "frmCustomer" and you want to use the "frm" naming prefix for all
your
> form variables, then what exactly do you name the form variable,
> "frmCustomer"? This wont work because that's the name of the form class.
You
> could put something on the end to make it differnt than the form class'
> name, like "frmCustomer1", but that would be sloppy and random. Does
anyone
> use a good methodical way of naming these types of things in VB.NET?

> Thanks!

> --Aron, MCP, MCSD, MCT



Tue, 27 Jul 2004 10:25:27 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. I am learning VB.NET and am wondering....

2. i am using vb.net and crystal reports for visual studio.net

3. I am writing a book about VB .NET, and I need your help you

4. Class name of VB components in different versions

5. Printing..... different way in Vb.Net

6. VB.NET How Do I Run MDI-Child On Different Thread

7. Installing VB.NET Windows Service on different machine.

8. Help reqd on ports identifying different hardware devices connected to the system in vb.net

9. Help understanding why byte arrays are different in c# and vb.net

10. VB.NET and C# have any different?

11. different versions of VB.Net??

12. Difference between VB NET and VB NET 2003

 

 
Powered by phpBB® Forum Software