Results 1 to 9 of 9

Thread: vb.net .vb files

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    vb.net .vb files

    If you can write all your classes in a single file in .net because you can declare classes unlike VB6, what are reasons you would have multiple class files in your application?

    I can only thing of 2 and that is
    1) if you have a ton of classes it can help to organize them (but so do code regions)
    2) so you could use them in another project by just adding that .vb file that contains the class in it

    if there are other reasons please let me know, just trying to figure out the best way to organize code going forward developing in .net

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Id only do it if I wanted to have multiple classes under the same namespace for reasons of similarity. otherwis. id keep em seperate.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    could you explain a little more

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Your reasons are mostly right.

    What I believe the poker is basically saying is that it would be logical to have Class X and Class Y in the same .VB file if you've created your namespace, and want X and Y to fall under that namespace. Otherwise, if they're simply classes for your app, you can avoid the cluttered code (Code regions don't do that much anyways) by placing them into separate files.

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Also, consider a Form like MyForm.vb

    Public Class MyForm
    Inherits Form
    .
    .
    .
    End Class

    When you double click this in the solution explorer the designer opens.

    If you add a new class in the bottom of that file, you only get the code when double clicking, becase the IDE doesn't see it as a regular form anymore.

    At least, thats with 2002.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I can't see any other advantages than what you've mentioned . Under organization , you can have your base class in a .vb file and each of the inherited classes in separate files , Enums or Structs in an other file , would be more organized . and so on . Just see any source code for these big projects in sourceforge and mimic the way they put classes together .

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    when you should make a namespace? should every .vb file that contains classes you wrote generally be under a namespace for easy access to it?

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    This is another major reason for seperating each class into a seperate file.

    3. When working on a multi developer project, if each class is in a seperate file, you can check out only one class that you are working on, and not 50 since VSS will lock the file, not the class.

    That right there is the MOST important reason for seperation. If you don't work with other developers in a source controlled environment, then you don't need to.

    By the way, if you have the same namespace in different files, those classes are still in the same namespace, they are just seperated out into seperate files. So the argument of keeping the classes in the same namespace doesn't hold up.

    I will only put two or more classes in the same code file only if those classes are tightly coupled, and they will never be seperated.

    Still, when you have a big project, and you are trying to find a class, I hate searching through different files trying to find it. It is so easy if each file represents a class. You just find the file, double click it, and you have your class.

    Just my thoughts..

  9. #9
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    look at it this way. Say you have four classes Called:

    Eyes
    Ears
    Nose
    Mouth

    It might be logical to group them under 1 namespace called Head. namespaces are just an organizational thing.

    By the way, if you have the same namespace in different files, those classes are still in the same namespace, they are just seperated out into seperate files. So the argument of keeping the classes in the same namespace doesn't hold up.
    Well I didnt say they HAD to be in 1 file. But its much easier to find the class you want under a namespace rather than dig through multiple files to find the right one.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width