Results 1 to 20 of 20

Thread: Organization of VB6 Source Code

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2020
    Posts
    796

    Organization of VB6 Source Code

    We know that the organization of VB6 source code is done by Module, Class, Form, UserControl, ActiveX-DLL, ActiveX-Control. I wonder if other programming languages (such as C#, Java, JS, TS, Golang, Rust, C++) have a better way of organizing source code than VB6? Thanks !

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,826

    Re: Organization of VB6 Source Code

    The primary thing that I'd like is sub-folders under each module type in the Project window. However, I've sort of already done that with the way I name my modules (particularly BAS modules), and I also create empty BAS modules (with names with a lot of dashes) that serve as module-group separators. It's not perfect, but it's better than nothing.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,815

    Re: Organization of VB6 Source Code

    Quote Originally Posted by SearchingDataOnly View Post
    We know that the organization of VB6 source code is done by Module, Class, Form, UserControl, ActiveX-DLL, ActiveX-Control. I wonder if other programming languages (such as C#, Java, JS, TS, Golang, Rust, C++) have a better way of organizing source code than VB6? Thanks !
    Dot net still has the concept of Classes, Structs, Forms, Controls, and Modules if VB - however they are all really just Classes or Structs under the hood. Rather than ActiveX Dlls etc. Anything (more or less) that can be written in dotnet can be made into a Dll for reuse.

    It gives a lot more flexibility with the physical structure though, files can be in sub folders, a file can contain more than one type, types can be nested, a type can be split over multiple files (partial types) etc.

    Also with .Net you have the logical aspect of organisation - namespaces, these allow code to be grouped in a more meaningful way regardless of the physical structure; this can even mean a single namespace can be spread over multiple Dlls as an example.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,175

    Re: Organization of VB6 Source Code

    In Lazarus/Freepascal i like the Unit-System

    Write your own Unit with Functions, types, Classes (multiple classes per Unit!), Constants, dirty socks, discarded girlfriends, whatever.
    You can put everthing into one and the same unit.

    Save the Unit somewhere on Disk (where you have your own units organised), add the path in the Lazarus-IDE, and you're done.
    No adding modules to project. Just put your unit in the uses clause where you need it, and go
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2020
    Posts
    796

    Re: Organization of VB6 Source Code

    Quote Originally Posted by Elroy View Post
    The primary thing that I'd like is sub-folders under each module type in the Project window. However, I've sort of already done that with the way I name my modules (particularly BAS modules), and I also create empty BAS modules (with names with a lot of dashes) that serve as module-group separators. It's not perfect, but it's better than nothing.
    I also often group my dozens of modules and hundreds of classes by adding underscores to their names, but I run into a big problem that module and class names cannot exceed 39 characters (to be precise, the project name + class names cannot be longer than 41 characters), this little limitation in VB6 is causing me a lot of trouble.
    Last edited by SearchingDataOnly; May 12th, 2022 at 09:47 AM.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2020
    Posts
    796

    Re: Organization of VB6 Source Code

    Quote Originally Posted by PlausiblyDamp View Post
    Dot net still has the concept of Classes, Structs, Forms, Controls, and Modules if VB - however they are all really just Classes or Structs under the hood. Rather than ActiveX Dlls etc. Anything (more or less) that can be written in dotnet can be made into a Dll for reuse.

    It gives a lot more flexibility with the physical structure though, files can be in sub folders, a file can contain more than one type, types can be nested, a type can be split over multiple files (partial types) etc.

    Also with .Net you have the logical aspect of organisation - namespaces, these allow code to be grouped in a more meaningful way regardless of the physical structure; this can even mean a single namespace can be spread over multiple Dlls as an example.
    .Net's Nampespace is a feature I really envy and aspire to have in VB6. In addition, .Net's Structs are much more powerful than VB6's UDTs, which makes code organization more convenient.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2020
    Posts
    796

    Re: Organization of VB6 Source Code

    Quote Originally Posted by Zvoni View Post
    In Lazarus/Freepascal i like the Unit-System

    Write your own Unit with Functions, types, Classes (multiple classes per Unit!), Constants, dirty socks, discarded girlfriends, whatever.
    You can put everthing into one and the same unit.

    Save the Unit somewhere on Disk (where you have your own units organised), add the path in the Lazarus-IDE, and you're done.
    No adding modules to project. Just put your unit in the uses clause where you need it, and go
    Lazarus/Freepascal's Unit-System seems very tempting, but I know very little about it. I'll take the time to understand it carefully. Thank you, Zvoni.

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,610

    Re: Organization of VB6 Source Code

    In addition to the things mentioned previously in the thread I'd add that .Net, C++, Python and just about every OO language out there also allows you to declare multiple classes in a single file, something lacking in VB6. Even something this simple thing goes a long way towards allowing better organization of code. Even TwinBASIC allows you to do this when last I checked.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  9. #9
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,815

    Re: Organization of VB6 Source Code

    Not necessarily source code but most modern languages (dotnet, java, python, even php and javascript) have some form of artefact / library management as well. e.g. Dotnet's nuget, npm etc for javascript, pip for python to make it easier to work with precompiled or pre-packaged libraries. These systems allow you to easily reference a package in a project / build file and specify a version, this then takes care of downloading the package, downloading dependencies, updating project references etc. all of which make it far easier to work with libraries (3rd party or your own)

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2020
    Posts
    796

    Re: Organization of VB6 Source Code

    Quote Originally Posted by Elroy View Post
    The primary thing that I'd like is sub-folders under each module type in the Project window. However, I've sort of already done that with the way I name my modules (particularly BAS modules), and I also create empty BAS modules (with names with a lot of dashes) that serve as module-group separators. It's not perfect, but it's better than nothing.
    Hi Elroy, could you give an example of your approach? Thanks.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2020
    Posts
    796

    Re: Organization of VB6 Source Code

    Quote Originally Posted by PlausiblyDamp View Post
    Not necessarily source code but most modern languages (dotnet, java, python, even php and javascript) have some form of artefact / library management as well. e.g. Dotnet's nuget, npm etc for javascript, pip for python to make it easier to work with precompiled or pre-packaged libraries. These systems allow you to easily reference a package in a project / build file and specify a version, this then takes care of downloading the package, downloading dependencies, updating project references etc. all of which make it far easier to work with libraries (3rd party or your own)
    Yes, if there are good plugins, it can greatly increase the efficiency of code organization and project development.

    Quote Originally Posted by Niya View Post
    In addition to the things mentioned previously in the thread I'd add that .Net, C++, Python and just about every OO language out there also allows you to declare multiple classes in a single file, something lacking in VB6. Even something this simple thing goes a long way towards allowing better organization of code. Even TwinBASIC allows you to do this when last I checked.
    Yes, I'm thinking about a question:

    In VB.Net and twinBasic, it is possible to put the definitions of multiple classes in a single file (eg MyModule1.vb). So can we develop a plug-in for VB6-IDE, read the definitions of multiple classes from MyModule1.vb through this plug-in, and plug them into VB6-IDE? That is to say, can we extend the features of VB6-IDE through MyModule1.vb, so that VB6-IDE can provide better code organization?

  12. #12
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    7,610

    Re: Organization of VB6 Source Code

    Well I have no knowledge of Visual Studio's plug-in architecture so I can't say if it would be possible to enhance the VB6 IDE in this way. Trick would know though.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,826

    Re: Organization of VB6 Source Code

    Quote Originally Posted by SearchingDataOnly View Post
    Hi Elroy, could you give an example of your approach? Thanks.
    Name:  ProjectWindow.jpg
Views: 216
Size:  154.9 KB
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2020
    Posts
    796

    Re: Organization of VB6 Source Code

    Very clever way, thank you Elroy.

  15. #15
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,477

    Re: Organization of VB6 Source Code

    Quote Originally Posted by Zvoni View Post
    In Lazarus/Freepascal i like the Unit-System

    Write your own Unit with Functions, types, Classes (multiple classes per Unit!), Constants, dirty socks, discarded girlfriends, whatever.
    I like Lazarus. I keep my constants, ie. discarded girlfriends somewhere they can be easily reloaded.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  16. #16
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,175

    Re: Organization of VB6 Source Code

    Quote Originally Posted by yereverluvinuncleber View Post
    I like Lazarus. I keep my constants, ie. discarded girlfriends somewhere they can be easily reloaded.

    Like a constant array?
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  17. #17
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    3,302

    Re: Organization of VB6 Source Code

    Have you look at this addin?

    Also, if you use the CodeSMART addin, the Project Explorer has a 'Logical' view instead of the default 'Physical' where you can create folders to group things in, no subfolders though.

  18. #18
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,826

    Re: Organization of VB6 Source Code

    I tend to keep my constants close to whatever functionality is using them. Now sure, I've got a few globally used constant, but even then, they're kept close to similar functionality. As a good example, because I do late-binding for Word automation, I've had to declare a bevy of the Word VBA's constants in my project. But I also have a module for doing certain Word automation things. (It can be seen above in that screen grab: mod_Gen_Word.) All my Word constants are in there.

    Regarding other cases (subclassing for instance), I've gotten to where I'll even declare constants inside a local procedure. I'd even declare some API calls within procedures if that were allowed. It just makes copy-pasting them easier. For example:

    Code:
    Private Function RtbForLinkEvent_Proc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
        If uMsg = WM_DESTROY Then
            UnSubclassSomeWindow hWnd, AddressOf_RtbForLinkEvent_Proc, uIdSubclass
            RtbForLinkEvent_Proc = NextSubclassProcOnChain(hWnd, uMsg, wParam, lParam)
            Exit Function
        End If
        If IdeStopButtonClicked Then ' Protect the IDE.  Don't execute any specific stuff if we're stopping.  We may run into COM objects or other variables that no longer exist.
            RtbForLinkEvent_Proc = NextSubclassProcOnChain(hWnd, uMsg, wParam, lParam)
            Exit Function
        End If
        '
        Const WM_NOTIFY         As Long = &H4E&
        Const EM_GETTEXTRANGE   As Long = &H44B&
        Const EN_LINK           As Long = &H70B&
        Const WM_LBUTTONDOWN    As Long = &H201&
        '
        Dim uHeader As NMHDR
    
        ...
    Last edited by Elroy; May 16th, 2022 at 05:32 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  19. #19
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    37,412

    Re: Organization of VB6 Source Code

    Better is in the eye of the beholder, but I'd suggest that there is also a worse way. I've always felt that the way header files worked in C/C++ was particularly awkward. It may be that this is no longer the case, though, since I have not used a modern C/C++ compiler directly. They made a certain amount of sense back in the 90s, and earlier. They weren't great, it's just that neither were the compilers.
    My usual boring signature: Nothing

  20. #20
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,826

    Re: Organization of VB6 Source Code

    Quote Originally Posted by Shaggy Hiker View Post
    Better is in the eye of the beholder, but I'd suggest that there is also a worse way.
    Yeah, I completely agree with that, both aspects of it. For me, especially when starting some new little project that I think is going to be fairly trivial. For those projects, I often don't pay much attention to organization. However, quite often, those trivial projects grow into something more substantial, with the module and form count doubling, tripling, or more.

    For me, when this happens, it's often quite useful to step back and take some time to do some re-organizing, possibly renaming variables so they're more consistent, refactor and retest (particularly edge condtions) code that was initially sloppily written, and reread and possibly expand on comments. When I step back and take some time to do this, it's often like the project has a big breath of fresh air.
    Last edited by Elroy; May 17th, 2022 at 08:45 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

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