-
Mar 19th, 2023, 10:52 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] declaration in usercontrol
I'm developing a component that has several usercontrols. In these UC it has declarations that are identical in practically all UC. When using the compiled component, would this use more memory? Or should I declare everything in a module?
I'm referring to Constants and Enums, example:
Code:
Private Const DT_LEFT = &H0
Private Const DT_CENTER = &H1
Private Const DT_WORDBREAK = &H10
Private Const GWL_EXSTYLE = -20
Private Const WS_EX_TOOLWINDOW = &H80
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const WM_NCMBUTTONDOWN = &HA7&
Private Const WM_NCRBUTTONDOWN = &HA4&
Private Const WM_NCLBUTTONDOWN = &HA1&
'enums
Private Enum DST_DSS
DST_COMPLEX = 0&
DST_ICON = &H3&
DSS_DISABLED = &H20&
End Enum
Obviously, if I make them public, this will show up in VB6 intellisense, and I didn't want that ...
-
Mar 19th, 2023, 11:33 AM
#2
Re: declaration in usercontrol
 Originally Posted by Episcopal
I'm developing a component that has several usercontrols. In these UC it has declarations that are identical in practically all UC. When using the compiled component, would this use more memory? Or should I declare everything in a module?
I'm referring to Constants and Enums, example:
Code:
Private Const DT_LEFT = &H0
Private Const DT_CENTER = &H1
Private Const DT_WORDBREAK = &H10
Private Const GWL_EXSTYLE = -20
Private Const WS_EX_TOOLWINDOW = &H80
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const WM_NCMBUTTONDOWN = &HA7&
Private Const WM_NCRBUTTONDOWN = &HA4&
Private Const WM_NCLBUTTONDOWN = &HA1&
'enums
Private Enum DST_DSS
DST_COMPLEX = 0&
DST_ICON = &H3&
DSS_DISABLED = &H20&
End Enum
Obviously, if I make them public, this will show up in VB6 intellisense, and I didn't want that ...
Constants should be resolved to the actual value at compile time, there will be no overheads at runtime from using a constant.
-
Mar 19th, 2023, 03:05 PM
#3
Re: declaration in usercontrol
Episcopal, you will use slightly more memory from duplicating your constants in several modules. However, with the small number of constants you're talking about, it's not going to matter one way or another. Sure, if you want to be ultra-efficient, then declare them all in a Constants.bas module, but I often do precisely what you did. In fact, I've actually gone the other direction through the years ... declare the constants I need in the procedures that use them. Doing it that way makes it much easier to reuse code via copy-paste.
Also, I'm not sure you have a complete grasp of Intellisense. Intellisense has a singular "symbol" table where all variable, constant, & procedure names are stored. Because of this, you can sometimes get some funny results ... for instance, if you change the upper/lower case of a variable (or constant or procedure name) in one place, it'll change that case everywhere, even if it's a separately scoped variable. Now sure, yes, Intellisense does keep track of the "scope" of things such that you don't see constant (or variable or procedure) names that aren't available to you (which is what you were talking about).
Last edited by Elroy; Mar 19th, 2023 at 03:08 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.
-
Mar 19th, 2023, 04:48 PM
#4
Addicted Member
Re: declaration in usercontrol
Personally, I like to put all the constants into the main module, then comment-out the duplicate "private" version. If needed, just comment a note where the constants will be used. (I'm not sure how many constants you have. You can also narrow it down to just the ones you need. Further, you can remove them completely, if you just put the actual value where you are using them.)
'#### User Control MyButton, MySlider, MyCheckbox Constants ####
It is said that VB6 just removes the constants and sets the actual values where they are used, when compiled...
Const x = 1
Const y = 1
Const z = 2
a = x + y + z
... Would become, when compiled... (constants removed)
a = 1 + 1 + 2
Just don't quote me on that... Because I have also heard otherwise, but it may only be in certain situations. You would have to compile a program with a few const and some uses, and hex the exe to see if that is really true or not. :P
-
Mar 19th, 2023, 05:02 PM
#5
Re: declaration in usercontrol
"Component" means "control." Not sure what you are trying to say, maybe "library" instead?
-
Mar 20th, 2023, 09:16 AM
#6
Thread Starter
Hyperactive Member
Re: declaration in usercontrol
 Originally Posted by dilettante
"Component" means "control." Not sure what you are trying to say, maybe "library" instead?
Exactly, the component would be a control .... a RibbonBar ..... other UC would be the buttons and other controls like combos, List, Galleries.
I know that computers today have more processing power and memory... but I always dry things out
-
Mar 20th, 2023, 12:15 PM
#7
Re: declaration in usercontrol
 Originally Posted by Episcopal
... but I always dry things out
Yeah, wet code is the pits.
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.
-
Mar 27th, 2023, 08:24 AM
#8
Thread Starter
Hyperactive Member
Re: declaration in usercontrol
 Originally Posted by Elroy
declare the constants I need in the procedures that use them
I think I'll go this direction....
-
Mar 27th, 2023, 11:27 AM
#9
Re: declaration in usercontrol
 Originally Posted by Episcopal
I think I'll go this direction....
It sure makes for nice copy-paste portable source code. And truly, the extra tiny bit of memory it costs you is infinitesimal in the broader scheme of things.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|