+ Reply to Thread
Results 1 to 5 of 5

Why does VBA allow some declarations to be changed by later references

  1. #1
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Why does VBA allow some declarations to be changed by later references

    It's a Saturday morning, and I gad a couple of minutes froo to explore something which has been bugging me for some time.

    I have a module which declares and defines an Enum:

    Please Login or Register  to view this content.
    With pretty well every other declaration, the capitalization I use to define values and variables is cast in concrete at the point where I define/declare them.

    As an example:
    Please Login or Register  to view this content.
    Then later on, no matter how I reference it (eg):
    Please Login or Register  to view this content.
    VBA will kindly impose the capitalization with which I defined it, and it shows up (after a split-second) as:
    Please Login or Register  to view this content.
    I like this. I can have fun with the declaration, and provided I get it 'right' (ie what I want to have be used everywhere), VBA will enforce it with nary a disapproving glance.

    Not so with my poor old Enum (and occasionally with other constants). If I set up the declaration given above:
    Please Login or Register  to view this content.
    where are all the Option values are preceded by a lower case "o", then adopt my admittedly lazy way of referencing them, VBA simply allows whatever I use as the most recent reference to replace the original declaration:

    Please Login or Register  to view this content.
    changes the original declaration and the rest of the module - if not the project to the new capitalization. In defence of VBA all I can say is that it is equally non-judgmental, and does it silently without comment.

    It makes debugging very difficult! And it looks ghastly.

    Now - there is obviously some code somewhere in the IDE which 'normalizes' capitalization. It's just that it looks as if the lines of code are in the wrong sequence for this use case. I'm imagining something like:

    Please Login or Register  to view this content.
    But for this particular case we get:
    Please Login or Register  to view this content.
    Has anybody else noticed this? And does it bug you as much? And if so, how do you deal with it (except painfully to correct it after each egregious change)?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Why does VBA allow some declarations to be changed by later references

    I do not know the answer to your question about why this happens. However, VBA code is case-insensitive. The automatic application of capitalization for a declared variable is just for formatting. The following will get you a compile error:
    Please Login or Register  to view this content.
    They are the same variable name as far as VBA is concerned.

    So I get that the behavior you are seeing for Enum value names is annoying, but it's not material. Not sure how it affects your debugging.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Why does VBA allow some declarations to be changed by later references

    I agree with your statements, Jim. I applaud the decision to make VBA case-insensitive (one of the biggest design flaws of C, IMHO).

    However, when looking at a line of code where the capitalization has been changed from a (hopefully less eccentrically) carefully constructed Camel Capitalization which has been inadvertently reformatted to all lower case (by my haste and admitted laziness) it doesn't affect the code, but it can take a few seconds(/minutes?) to figure out just what this nice meaningful long name really was.

    I can certainly love with this strange behaviour, but it's the inconsistency that bugs me.

    Thanks for your comment,

    Tony

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Why does VBA allow some declarations to be changed by later references

    I agree with how it bugs you, Troy. I don't know if it's intentional, but if it's a bug you would think they could have fixed it after a couple of decades.

  5. #5
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Why does VBA allow some declarations to be changed by later references

    I'm with you, 6String, but I'm sure you know that after a couple of years things like this must be left alone, by company policy in case fixing it breaks something for someone (!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. External references changed when sheet is closed and reopened
    By crct in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-05-2018, 06:37 AM
  2. Problem with declarations it seems
    By sbe70 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2014, 06:09 AM
  3. problem with syntax on simple Class declarations and Sub declarations
    By ocean_engineer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-28-2011, 03:59 AM
  4. Cell References Changed
    By AB2537 in forum Excel General
    Replies: 0
    Last Post: 03-14-2006, 11:50 AM
  5. Cross worksheet references cannot be easily changed
    By maintchief in forum Excel General
    Replies: 0
    Last Post: 11-25-2005, 11:35 PM
  6. declarations
    By jimbo_jones in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2005, 01:50 PM
  7. Declarations Procedure and Duplicate Declarations
    By Neal Zimm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2005, 08:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1