Results 1 to 9 of 9

Thread: [RESOLVED] declaration in usercontrol

  1. #1

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Resolved [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 ...

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: declaration in usercontrol

    Quote Originally Posted by Episcopal View Post
    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.

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

    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. To all, peace and happiness.

  4. #4
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    181

    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

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

    Re: declaration in usercontrol

    "Component" means "control." Not sure what you are trying to say, maybe "library" instead?

  6. #6

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: declaration in usercontrol

    Quote Originally Posted by dilettante View Post
    "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

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

    Re: declaration in usercontrol

    Quote Originally Posted by Episcopal View Post
    ... 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. To all, peace and happiness.

  8. #8

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: declaration in usercontrol

    Quote Originally Posted by Elroy View Post
    declare the constants I need in the procedures that use them
    I think I'll go this direction....

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

    Re: declaration in usercontrol

    Quote Originally Posted by Episcopal View Post
    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. 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