Results 1 to 34 of 34

Thread: [RESOLVED] Static Functions of VB6

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Resolved [RESOLVED] Static Functions of VB6

    I accidentally discovered that Static can be used to decorate Function, for example:
    Code:
    Static Function MyFunc()
    
    End Function
    But this usage seems to be less valuable than the Static-Function of the C++ class. Do we have a way to implement Static-Function similar to C++ class? Thanks.

  2. #2
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Static Functions of VB6

    They should be the same. Static is Static.
    What differences are you seeing?

  3. #3
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    370

    Re: Static Functions of VB6


  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Static Functions of VB6

    Quote Originally Posted by vb6forever View Post
    They should be the same. Static is Static.
    What differences are you seeing?
    In C++, static functions can be used like VB6 module functions, for example:
    Code:
    Class1.MyFunc();         //No need to use the new operator

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Static Functions of VB6

    Quote Originally Posted by SearchingDataOnly View Post
    In C++, static functions can be used like VB6 module functions, for example:
    Code:
    Class1.MyFunc();         //No need to use the new operator
    If you implement lightweight COM-Classes in VB6, you'll do that in *.bas Modules as well -
    and then the "Static" functions are just "Public" functions in such a Module.

    Olaf

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

    Re: Static Functions of VB6

    This is what one of those poisonous relics from VB's long history. If one ever needs to use a Static Function, they they are doing it wrong. The general consensus is that this type of static function violates several good practice programming principles but I won't go in to all that. There are plenty of people way smarter than me that can explain all that better.

    As for how it compares to other languages, you have to be very careful here. Static VB6 functions are very different from static functions in other languages. Static functions in VB6 preserve their variables between calls which I believe was the main intent and it's also the reason why a lot of people consider it bad. Static functions in C mean they are only visible to other functions in the file in which the static function is implemented. Static methods in languages like C++, C#, VB.Net means that the methods belong to the entire class and not a particular instance of the class.

    Static functions/methods can mean very different things in different languages.
    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

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Static Functions of VB6

    People also get confused by the Friend decorator. Friend members are "public" but only within the compilation unit (EXE, DLL/OCX).

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

    Re: Static Functions of VB6

    Quote Originally Posted by dilettante View Post
    People also get confused by the Friend decorator. Friend members are "public" but only within the compilation unit (EXE, DLL/OCX).
    Friend is extremely useful when you when to want to share functionality internally but hide it from public consumers of your component. Very underrated access modifier.
    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
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Static Functions of VB6

    Quote Originally Posted by Niya View Post
    Friend is extremely useful when you when to want to share functionality internally but hide it from public consumers of your component. Very underrated access modifier.
    That sounds like a retelling of the old joke: A friend is somebody who will help you move. A good friend is somebody who will help you move...a body.

    Your first sentence is the programmatic version of that.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Static Functions of VB6

    Quote Originally Posted by Schmidt View Post
    If you implement lightweight COM-Classes in VB6, you'll do that in *.bas Modules as well -
    and then the "Static" functions are just "Public" functions in such a Module.

    Olaf
    Yes, lightweight COM-Classes can simulate C++ static functions well in VB6. Thank you, Olaf.

    Edit:
    For me, there seems to be a lot of secrets hidden in VB6, and these secrets may greatly expand the scope of application of VB6.
    Last edited by SearchingDataOnly; Aug 2nd, 2021 at 11:47 AM.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Static Functions of VB6

    Quote Originally Posted by Niya View Post
    This is what one of those poisonous relics from VB's long history. If one ever needs to use a Static Function, they they are doing it wrong. The general consensus is that this type of static function violates several good practice programming principles but I won't go in to all that. There are plenty of people way smarter than me that can explain all that better.

    As for how it compares to other languages, you have to be very careful here. Static VB6 functions are very different from static functions in other languages. Static functions in VB6 preserve their variables between calls which I believe was the main intent and it's also the reason why a lot of people consider it bad. Static functions in C mean they are only visible to other functions in the file in which the static function is implemented. Static methods in languages like C++, C#, VB.Net means that the methods belong to the entire class and not a particular instance of the class.

    Static functions/methods can mean very different things in different languages.
    I've used VB6 for many years, but I have never known that there is a "static function" in VB6. This "static function" is completely different from the static function in C++, so I will not use this function that few people use in VB6 for the time being.

  12. #12
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Static Functions of VB6

    Personally, I just tend to use the Static keyword on specific (procedure local) variable declarations if that's what I want, rather than making them ALL static by declaring the entire procedure as Static.

    Just making specific variables Static is more memory efficient, and makes for clearer source code IMHO.
    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. To all, peace and happiness.

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

    Re: Static Functions of VB6

    Quote Originally Posted by Shaggy Hiker View Post
    That sounds like a retelling of the old joke: A friend is somebody who will help you move. A good friend is somebody who will help you move...a body.

    Your first sentence is the programmatic version of that.
    LMAO! Very clever.

    Quote Originally Posted by SearchingDataOnly View Post
    I've used VB6 for many years, but I have never known that there is a "static function" in VB6. This "static function" is completely different from the static function in C++, so I will not use this function that few people use in VB6 for the time being.
    I've known about it for a long time. When I got older and started taking good design practices seriously, I decided to forget it ever existed. There is just no need for it and encourages a very bad way of thinking. I don't even know why Microsoft would even bother putting such an abomination into the language. To be honest, I'm not even too fond of static variables either. Something just feels dirty about static variables and I avoid them completely.
    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

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Static Functions of VB6

    Quote Originally Posted by Elroy View Post
    Personally, I just tend to use the Static keyword on specific (procedure local) variable declarations if that's what I want, rather than making them ALL static by declaring the entire procedure as Static.

    Just making specific variables Static is more memory efficient, and makes for clearer source code IMHO.
    Hi, Elroy, what you said is very reasonable. Before that, for me, the only usage of static was to decorate a specific (procedure local) variable. But this makes the static keyword too little useful.

    In my opinion, static should have 3 purposes:
    (1) Decorate procedure local variables
    (2) In Forms and Modules, playing the role of existing static function of VB6
    (3) In Classes, play the role of C++ static function.

    Of course, this is just an impossible dream.
    Last edited by SearchingDataOnly; Aug 2nd, 2021 at 12:24 PM.

  15. #15
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Static Functions of VB6

    I'm sure Static has a place, I'm just not sure it is a good choice most of the time.

    It helps you keep data local to the procedure, but usually when I consider it I immediately find I also need to craft some kludge to reset it on demand. At that point module-scope data makes more sense.

  16. #16
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Static Functions of VB6

    Quote Originally Posted by Niya View Post
    I'm not even too fond of static variables either.
    I don't use them terribly often, but there are two circumstances where I find them quite useful:

    1) When I'm writing some procedure that might be called repeatedly but takes a bit of initialization that I don't want to think about and don't want to write a separate procedure for. A good example is a "RndDbl" function I have that uses Crypt... (advapi32) calls, which require initialization.

    2) To stop unwanted recursion in certain events that may do things that cause themselves to recurse. I just set a boolean static, and immediately get out if it's true, setting it back to false when it ultimately drops out from the first time being raised.
    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. To all, peace and happiness.

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Static Functions of VB6

    Quote Originally Posted by Niya View Post
    I've known about it for a long time. When I got older and started taking good design practices seriously, I decided to forget it ever existed. There is just no need for it and encourages a very bad way of thinking. I don't even know why Microsoft would even bother putting such an abomination into the language. To be honest, I'm not even too fond of static variables either. Something just feels dirty about static variables and I avoid them completely.
    Yes, we should avoid some bad design in the code, just like we should avoid "Goto" and "On Error Resume Next", but sometimes in some special places (partial code), these keywords are very useful. Basically, I can manage these bad usages.

    Generally speaking, I pay a lot of attention to the design of the overall software architecture, and do my best in the architecture as much as possible. However, in some partial codes, I don't really pursue perfect design. During the actual application of the product, I'll gradually optimize the software according to the actual situation. In many cases, optimizing the code in advance will lead to waste of design and waste of resources.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Static Functions of VB6

    Quote Originally Posted by dilettante View Post
    People also get confused by the Friend decorator. Friend members are "public" but only within the compilation unit (EXE, DLL/OCX).
    Yes, the Friend decorator is a strange thing.

    Quote Originally Posted by dilettante View Post
    I'm sure Static has a place, I'm just not sure it is a good choice most of the time.

    It helps you keep data local to the procedure, but usually when I consider it I immediately find I also need to craft some kludge to reset it on demand. At that point module-scope data makes more sense.
    Agree.

  19. #19
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Static Functions of VB6

    Quote Originally Posted by SearchingDataOnly View Post
    Yes, the Friend decorator is a strange thing.
    Searching, I apologize in advance if this comes off as patronizing. But I don't find it strange (although some are confused by it). Microsoft convoluted things a bit by not allowing them in BAS modules. Personally, I'd like it if Friend and Public were just synonymous in BAS modules.

    But, as things stand, they're only allowed in class modules (including UCs, forms, and anything else that can be instantiated). To my mind, Friend in a CLS module is quite similar to Public in a BAS module ... both are "seen" project wide, but aren't exposed to anything outside of our project. The biggest advantage when used in CLS modules is that you can then pass your UDTs around within those modules.

    And, when Public is used in a CLS module, it has the potential to be exposed outside of the actual project (but other things must be done before that actually happens). And two downsides are that these Public CLS declarations cause your compiled code to be more complex, and use lose UDT functionality.

    Personally, when in any module that can be instantiated, I always use the Friend (or Private) declaration on procedures unless I'm doing something quite specific that requires a Public declaration.
    Last edited by Elroy; Aug 2nd, 2021 at 12:40 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. To all, peace and happiness.

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: Static Functions of VB6

    Quote Originally Posted by Elroy View Post
    Searching, I apologize in advance if this comes off as patronizing. But I don't find it strange (although some are confused by it). Microsoft convoluted things a bit by not allowing them in BAS modules. Personally, I'd like it if Friend and Public were just synonymous in BAS modules.

    But, as things stand, they're only allowed in class modules (including UCs, forms, and anything else that can be instantiated). To my mind, Friend in a CLS module is quite similar to Public in a BAS module ... both are "seen" project wide, but aren't exposed to anything outside of our project. The biggest advantage when used in CLS modules is that you can then pass your UDTs around within those modules.

    And, when Public is used in a CLS module, it has the potential to be exposed outside of the actual project (but other things must be done before that actually happens). And two downsides are that these Public CLS declarations cause your compiled code to be more complex, and use lose UDT functionality.

    Personally, when in any module that can be instantiated, I always use the Friend (or Private) declaration on procedures unless I'm doing something quite specific that requires a Public declaration.
    Sometimes, I want to use the Friend decorator in the interface, but it doesn't work. VB6 restricts a lot of usage, maybe its designer knows that we are all "low-level programmers".

  21. #21
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    557

    Re: [RESOLVED] Static Functions of VB6

    Language constructions and features are important when something will be implemented in specific language. VB modules are really specific compared to what other languages are having and require to implement similar functionality. Same with static keyword in VB6. Assuming same functionality just by similarity of keyword use in other language is wrong in most cases.

    This is the beauty of different languages - you can implement some patterns in so many different ways so it can suit different use cases. There is no need to have exactly same behavior of language structures to get same final result. Even if I am trying to limit some specific use cases of language constructs to allow faster languages translation of code when required, I prefer to use good practices where required. When some language dialect doesn't have a feature - do it in different way to get the proper code. Sometimes helper methods are required when in other languages this is natural feature (e.g. constructor parameters in VB6).

    The other discussed keyword Friend is also interesting. I really didn't knew that VB6 has that for long time. So I always started everything as private and only put to "public" use what is required to be used from other classes. When something was private but some module (not in the terms of VB6) require to have access to it - just change it to public after some analysis if that is really required. Adding the "friend" access modifier to the language features was another step in writing the code: first make everything private, then move what required to friend and finally to public (if not initially required it to be public in the software design phase).

    So my verdict is that it is not a keyword or feature of language. It is the proper software design and usage of what is known, not what other languages have (or are known to masses). When language evolves (sorry to mention VB.NET for all that hate it but it is language that evolved during last 20 years), the features set is improved during the time and developers should learn how to use them. Similar (to VB6) it may happen that something exists for many years but people don't know about it. With the internet age and now with many public source code repositories it is much easier to find and learn what other people know and how they do it.

    The reality is that VB6 has lots of features for the time it was developed. And good developers use them properly as they have wrote and seen lot of code in different languages; implemented different design patterns during the years; didn't stop evolving and overcome the limitations of the language.

    On the other side are people who don't try to overcome the limits. Rest is well known to internet forums :-))

  22. #22
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Static Functions of VB6

    Friend should be used very sparingly. It is not meant as a surrogate for Public. It sort of works for passing non-published UDTs, except when it fails.

    But we sometimes have to "misuse" some of these things in order to accomplish specific goals. It helps to understand their implications and the actual rules around them rather than trying to rely on simplistic "never use" mantras.

  23. #23
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    557

    Re: [RESOLVED] Static Functions of VB6

    Software design usually is not affected so much by language features. If your language supports only public vars and methods - everything will be public. The proper design is not affected by that fact. It will be more vulnerable to attacks but still working. When private will be added to language - the design is still the same, just the implementation will be better. Friend decorator is another step to improve the implementation. The SDS (software design specification - term from 20 years ago) will be the same. Same for all other sounding like (put your language like java script/type script, c/c++, go, java, kotlin, clojure, erlang, ..............................................) keywords that are missing but exist with different functionality.

    Is it strange that software design is almost non-discussed in this forum? Bad design cannot be helped with the best language features. And will never be.

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

    Re: [RESOLVED] Static Functions of VB6

    Quote Originally Posted by dilettante View Post
    Friend should be used very sparingly. It is not meant as a surrogate for Public. It sort of works for passing non-published UDTs, except when it fails.

    But we sometimes have to "misuse" some of these things in order to accomplish specific goals. It helps to understand their implications and the actual rules around them rather than trying to rely on simplistic "never use" mantras.
    I would preach the opposite. I default to Friend when building libraries, this allows me freedom to complicate the internal design as much as I want while keeping the public interfaces simple and clean.
    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

  25. #25

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: [RESOLVED] Static Functions of VB6

    Quote Originally Posted by peterst View Post
    Language constructions and features are important when something will be implemented in specific language. VB modules are really specific compared to what other languages are having and require to implement similar functionality.
    The vb6-module(bas) is a very valuable design, it's very useful when developing small software projects. But when developing large (or huge) projects, the vb6-module(bas) will show its limitations. Specifically, the vb6-module (bas) does not allow classes (inner classes) to exist in the module. VB.Net and twinBasic allow classes to be defined in modules, which allows the code in large/huge projects to be better organized and modularized.

    Quote Originally Posted by peterst View Post
    When some language dialect doesn't have a feature - do it in different way to get the proper code. Sometimes helper methods are required when in other languages this is natural feature (e.g. constructor parameters in VB6).
    Yes, we can implement VB6 constructor parameters indirectly through other means, but it seems difficult for us to simulate JS arrow functions, prototype programming, and so on.

    Quote Originally Posted by peterst View Post
    Software design usually is not affected so much by language features. If your language supports only public vars and methods - everything will be public. The proper design is not affected by that fact. It will be more vulnerable to attacks but still working. When private will be added to language - the design is still the same, just the implementation will be better. Friend decorator is another step to improve the implementation. The SDS (software design specification - term from 20 years ago) will be the same. Same for all other sounding like (put your language like java script/type script, c/c++, go, java, kotlin, clojure, erlang, ..............................................) keywords that are missing but exist with different functionality.

    Is it strange that software design is almost non-discussed in this forum? Bad design cannot be helped with the best language features. And will never be.
    Generally speaking, VB6 is an extremely well-designed language, which balances ease of use and development efficiency, while retaining a huge space for expansion (win-APIs and COM components). But in terms of extensibility, VB6 obviously has a huge gap with JavaScript.

    JavaScript was not a very good language at first, but due to its excellent (or even unlimited) extensibility, JS became the most popular language in the world under the continuous improvement of some of the smartest programmers , it's almost omnipotent.

    Now I'm most interested in exploring the extensibility of VB6 and looking for greater possibilities in VB6.
    Last edited by SearchingDataOnly; Aug 2nd, 2021 at 09:40 PM.

  26. #26
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: Static Functions of VB6

    Quote Originally Posted by Elroy View Post
    Personally, when in any module that can be instantiated, I always use the Friend (or Private) declaration on procedures unless I'm doing something quite specific that requires a Public declaration.
    Very good. Does this elevate safety in reverse engineering?

  27. #27
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: [RESOLVED] Static Functions of VB6

    Quote Originally Posted by SearchingDataOnly View Post
    Specifically, the vb6-module (bas) does not allow classes (inner classes) to exist in the module.
    Forgive me. But how so. Could you explain better or exemplify?

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

    Re: [RESOLVED] Static Functions of VB6

    Quote Originally Posted by Episcopal View Post
    Forgive me. But how so. Could you explain better or exemplify?
    He means that you cannot define classes inside the module file like you could in modern OO languages. VB6 requires every class be in it's own file with no other classes. Modern OO languages let you define classes pretty much wherever you want and you can define as many of them as you want in a single code file.
    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

  29. #29

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: [RESOLVED] Static Functions of VB6

    Quote Originally Posted by Niya View Post
    He means that you cannot define classes inside the module file like you could in modern OO languages. VB6 requires every class be in it's own file with no other classes. Modern OO languages let you define classes pretty much wherever you want and you can define as many of them as you want in a single code file.
    Yes, your explanation is clearer.

    I'm studying the lightweight-COM technology of vb6. If the lightweight-COM technology is used, then we can define many lightweight COM-Classes in one module file. However, doing so greatly reduces the readability of the code.

    The internal class and structure of VB.NET and twinBasic are what I really want. I don't know whether the lightweight COM-Classes can simulate the structure of VB.NET and twinBasic.
    Last edited by SearchingDataOnly; Aug 5th, 2021 at 06:10 AM.

  30. #30
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: [RESOLVED] Static Functions of VB6

    The internal class and structure of VB.NET and twinBasic are what I really want.
    There are about 2500 different programming languages if I recall correctly.
    Each has its plus and minuses.
    IMHO the key is not the language one uses to program in, but what the
    compiler does.

    If you want that ability, then why not use VB.NET and twinBasic.
    Personally I've never had a need for what you want -- I could be missing something regarding having that ability -- but
    as I see it, it is a one off.

    My2Cents

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

    Re: [RESOLVED] Static Functions of VB6

    Quote Originally Posted by SearchingDataOnly View Post
    Yes, your explanation is clearer.

    I'm studying the lightweight-COM technology of vb6. If the lightweight-COM technology is used, then we can define many lightweight COM-Classes in one module file. However, doing so greatly reduces the readability of the code.

    The internal class and structure of VB.NET and twinBasic are what I really want. I don't know whether the lightweight COM-Classes can simulate the structure of VB.NET and twinBasic.
    Actually, VB.Net is not special in this regard. I know of no OO language and I mean none that impose such a limitation. VB6 is the only OO language I'm aware of that with this limitation. C++ compilers also have the ability to create COM binaries so this limit has nothing to do with COM. It's an artificial limit with no benefit that I can see.

    I can speculate on one possible reason for this though. The classes themselves have properties like whether they are public COM classes so making them as 1 class per file would be the easiest way to implement this. This kind of thing would be harder to implement if multiple classes could be placed in one file. .Net languages like VB.Net and C# allow you to annotate classes with metadata aimed at the compiler which is a wee bit more complicated that simply pressing F4 and getting a nice little property grid to see the metadata.

    Quote Originally Posted by vb6forever View Post
    There are about 2500 different programming languages if I recall correctly.
    Each has its plus and minuses.
    IMHO the key is not the language one uses to program in, but what the
    compiler does.

    If you want that ability, then why not use VB.NET and twinBasic.
    Personally I've never had a need for what you want -- I could be missing something regarding having that ability -- but
    as I see it, it is a one off.

    My2Cents
    It's an exceptionally stupid limit and there is no excuse and I mean no excuse for it. No other language does this.
    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

  32. #32
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Static Functions of VB6

    Quote Originally Posted by Episcopal View Post
    Quote Originally Posted by Elroy View Post
    Personally, when in any module that can be instantiated, I always use the Friend (or Private) declaration on procedures unless I'm doing something quite specific that requires a Public declaration.
    Very good. Does this elevate safety in reverse engineering?
    I don't really know, but I'd argue that it does. It's probably going to compile into tighter code, without placing your procedure names in some table such that they can be easily seen with a hex editor (or, at least they're in one less table).

    However, with all of my stuff being open-source for years, this isn't stuff I typically worry about. I just like "Friend" because I can use UDTs, and I feel that it executes faster (although no proof there, but it's certainly testable).
    Last edited by Elroy; Aug 6th, 2021 at 02:30 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. To all, peace and happiness.

  33. #33
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: [RESOLVED] Static Functions of VB6

    Most importantly Friend cannot be called late-bound like Public. This is major in a big system esp. multi-project ones when you have to refactor a function prototype (e.g. modify the number of parameters).

    With Friend the compiler will fail immediately at every callsite while with Public you cannot be certain if the class is not used late-bound from some obscure place.

    This is problematic even for private classes (like custom Forms) as these can be explosed to other projects as plain IDispatch/Object references.

    cheers,
    </wqw>

  34. #34
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: [RESOLVED] Static Functions of VB6

    Quote Originally Posted by wqweto View Post
    Most importantly Friend cannot be called late-bound like Public. This is major in a big system esp. multi-project ones when you have to refactor a function prototype (e.g. modify the number of parameters).

    With Friend the compiler will fail immediately at every callsite while with Public you cannot be certain if the class is not used late-bound from some obscure place.

    This is problematic even for private classes (like custom Forms) as these can be explosed to other projects as plain IDispatch/Object references.

    cheers,
    </wqw>
    True ... but that's the specific case where you DO want to use Public, rather than Friend.

    And gosh, I suppose I can make a case where I might do it, but I'm not sure I've ever used a class (or form) within an EXE project where I use that class (or form) in a late-bound fashion.
    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. 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