Need help organizing Class files

Posted on 2006-06-02
Last Modified: 2010-04-07
I think .net has really spoiled me.
I'm trying to figure out a way to somewhat "organize" my class files.

Where in .net I can give each class file a name, the class code a name, and even add a namespace... is there anything that I can do remotely like this in VB6?

It feels like I am defeating the purpose of organizing the code if I am just dumping vb6 form-behind code into class modules.... if no organization possiblities exist...

Any help?
Question by:born4code
    LVL 22

    Expert Comment

    I'm not really sure what you're asking.
    In .Net, the Namespaces definitely help.

    In VB6, I usually just name all of my classes with a cls prefix so they sort together in the project.

    And all of your forms are really essentially classes so there's usually no need to move the code into a separate class.

    And if you don't need the features of a class, but just a common placeholder for code, make yourself a module.
    LVL 17

    Expert Comment

    Are you talking about sharing your classes across several projetcs?
    LVL 2

    Author Comment

    To clarify a bit more... let me give you an example...

    A class file name of Whatever.vb,
    A Class Name inside of the Whatever.vb file, let's  Public Class MyWhatever
    And, I can wrap the class with a namespace, like MyWhateverNamespace

    Your advice of just naming the files with the same alphabetical character

    Golly, isn't there something a little better than I can do in VB6 rather than just rename a file to a better name?  "I understand you logic that a form is a class anyway"... but I am trying to organize my code in class files and get as close to a .NET model as I possibly can.

    Sharing --- Not really.  Actually, however I have used a DLL like this in the past, inside of a project.  Is that what you are referring to?  Perhaps that is another way to tackle this?

    LVL 17

    Accepted Solution

    Yes was going to suggest that next, but the downside of DLLs is that if you are just using compiled DLLs it become a pain, but can be improved.......You can get a little closer to .net by coding with multiple projects simultaneously.

    So you create your Main project. You can also create another project, say with a project name like MyWhaterverNameSpace. When you want to test the entire application, you open your main project, select File-Add Project ans select the MyWhaterverNameSpace project. You can then click on the Main project and set a reference to the MyWhaterverNameSpace project.

    So in your Main project you can then define Public objects/variables within a standard module like this:

    Global MyWhaterverNameSpace.MyClass As MyClass

    Or make private declarations within other functions/classes

    Dim MyWhaterverNameSpace.MyClass As MyClass
    So anywhere within main project you can now use the properties/methods of MyClass.  The joy is that you can now change the code simultaneously in both projects.

    I use this strategy with several types of libraries, for example if have a GF (gereral functions with project name zGF) project, so at the top of forms, just type  Dim GF As New zGF. Or in a module Global GF As New zGF.

    So its kinda like Imports....
    LVL 22

    Expert Comment

    In all fairness, you're looking at older technology.  I think that VB6 showed up around the time of Windows 98.  It was good at the time, but we've obviously found better ways to do things.

    I personally like the DotNet #Region command for organizing code.  I wouldn't expect VB6 to have something that lets me easily organize code like that because it was a relatively new idea.

    Granted, namespaces are not new, but they were always very well hidden in previous versions of VB.

    I would suggest doing what you're doing (which is pretty good) and see if it's possible to start migrating this project to DotNet so you can take advantage of all the new features you like.
    LVL 2

    Author Comment


    sounds interesting.  i can vaguely remember doing something like this a long time ago...


    - I assume that the extra project I create is an "ActiveX dll project", and I must compile it
    - After compiling, it is available in the reference menu, which I point to that project etc..


    - After adding the new project reference, I make some changes to it (right there).
    - Now I need to compile my exe... don't I have to go BACK to the referred dll project and recompile the dll?

    Obviously, I would have to include the referenced dll in my setup package, yes?

    Thanks again.
    LVL 2

    Author Comment

    Oh yeah almost forgot..

    Do I have to remove the extra project when I get ready to deploy?  Or do I need BOTH the added project AND the reference?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now