+ Reply to Thread
Results 1 to 36 of 36

If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

  1. #1
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    For some absurd reason, on my 2 years old Excel ("Excel for Microsoft 365 MSO (16.0.13127.21062) 64-bit")
    the following "TEST" function go inside(!) the If... Then... generating the MsgBox, whatever test is done by the If,
    while the current version of Excel (standard channel, 64-bit) correctly jumps to the "End If" bypassing the MsgBox instruction.

    Does this happen with your Excel version too?
    Is it a confirmed bug? (it seems very dangerous!)

    Module Module1:
    Please Login or Register  to view this content.
    Class MainClass:
    Please Login or Register  to view this content.
    Class SubClass:
    Please Login or Register  to view this content.
    MacroBug.xlsm file, ready to test

    Screenshot:
    Immagine 2022-10-09 134432.jpg
    Last edited by 6diegodiego9; 10-09-2022 at 08:49 AM.

  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: Absurd VBA bug with 2yrs old Excel version!

    I get a compile error here. I am not familiar with a subclass feature built into VBA. I do not have a SubClass option available in Intellisense when I write a Dim statement and when I click F1 for help on it I get a "Keyword not found" page. Perhaps you can give a little more explanation about that.

    As Subclass error.jpg
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70
    I just corrected some typos. Can you please try to copy and paste it again?
    Last edited by AliGW; 10-09-2022 at 06:54 AM. Reason: Please DON'T quote unnecessarily!

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Absurd VBA bug with 2yrs old Excel version!

    I can't replicate the error.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    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: Absurd VBA bug with 2yrs old Excel version!

    I get the same compile error.

    @mikerickson how are you not getting the compiler error I get?

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Absurd VBA bug with 2yrs old Excel version!

    The SubClass is another class object. So code is in 3 code modules called Module1, MainClass and SubClass

    I do not get the compile error nor do I get the bug of the If test returning False.
    But I don't have 64bit to properly test.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: Absurd VBA bug with 2yrs old Excel version!

    I don't get compiler error, anyway here is the xlsm file ready to test: MacroBug.xlsm

    Screenshot:
    Immagine 2022-10-09 134432.jpg
    Last edited by 6diegodiego9; 10-09-2022 at 08:47 AM.

  8. #8
    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: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by 6diegodiego9 View Post
    For some absurd reason
    6diegodiego9, you have edited your original post at least 15 times since first posting. This causes a lot of confusion. I got a compile error because you specified "SubCls" and didn't say what kind of module it was, but much later you clarified that this should be a "Class named SubClass".

    Please avoid editing a post after people have already responded to it. If you really must do so, then indicate exactly what you have changed.

  9. #9
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    @6diegodiego9, this works;

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by 6StringJazzer View Post
    6diegodiego9, you have edited your original post at least 15 times since first posting. ...
    Yes sorry, my edits were just corrections to the SubCls - SubClass typos (causing compiler error to you) and other aesthetic changes to make it all more clear.
    Last edited by AliGW; 10-10-2022 at 02:44 AM. Reason: Please DON'T quote unnecessarily!

  11. #11
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by Haluk View Post
    @6diegodiego9, this works; ...
    I actually found two workarounds to the problem, like you did. However, I'd like to understand why it happens, to avoid repeating the same bugged(?!) code in future, on that 2 years old Excel.

    Do you have the problem with my original code?
    Last edited by AliGW; 10-10-2022 at 02:44 AM. Reason: Please DON'T quote unnecessarily!

  12. #12
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    The logic is; you have to initiate your class and then do your comparison in the If Block.

    May be the code below will be more easy to understand, where you don't need the "Function obj() As MainClass" in your module.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    My code was simplified from a real case where I need the function as parameterized constructor, to create new (disposable) objects depending on parameters (that I pass to the function).

    I need it to instantiate the obj using the function. Does it work (with the function) with your Excel version?
    Last edited by AliGW; 10-10-2022 at 02:43 AM. Reason: Please DON'T quote unnecessarily!

  14. #14
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Your original does not work because of the facts I've explained before.

    If you need that function, just leave it.

  15. #15
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    If the fact that you explained before was that I didn't instantiate the class, I don't understand because of two reasons:
    - I wrote "Set obj = New MainClass" inside the called function, this is where I instantiated it
    - the whole code works correctly (doesn't go inside the If) with my updated Excel, while works uncorrectly (go inside the If) only with my 2 years old Excel
    Last edited by AliGW; 10-10-2022 at 02:43 AM. Reason: Please DON'T quote unnecessarily!

  16. #16
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    What I am trying to explain is that; you are not using "Function obj()" properly.

    In the below code, the function is called and assigned to a object and then the rest of the code is executed with that assigned object.

    Please Login or Register  to view this content.
    This is what I can say ....

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    My guess would be that it was a bug that was fixed subsequently, whether acknowledged or not.
    Remember what the dormouse said
    Feed your head

  18. #18
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by Haluk View Post
    What I am trying to explain is that; you are not using "Function obj()" properly.
    Is this documented somewhere?
    Why I don't get an error? why does it give the correct result if executed with my updated Excel instead?

  19. #19
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by rorya View Post
    My guess would be that it was a bug that was fixed subsequently, whether acknowledged or not.
    So, should we avoid to use such a pattern in all distributed VBA code to avoid executing unexpected code without even getting an error? I am scared of this...

  20. #20
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by 6diegodiego9 View Post
    So, should we avoid to use such a pattern in all distributed VBA code to avoid executing unexpected code without even getting an error? I am scared of this...
    Working on that basis, you'd never write any code in case there was a bug in some version of Excel.

  21. #21
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by rorya View Post
    Working on that basis, you'd never write any code in case there was a bug in some version of Excel.
    Does the bug verify on your Excel too?

  22. #22
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by 6diegodiego9 View Post
    Is this documented somewhere?

    See this;

    https://www.oreilly.com/library/view...58-fm2xml.html

  23. #23
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    No, mine has no problem with the original code.

  24. #24
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    @rorya;

    Did you try my alternatives and get any unexpected results?

  25. #25
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    No I didn't, since the OP said he already had workarounds. I was merely addressing the issue of the bug (since the code should work, and does in 2016 and current 365, both Mac and Windows).

  26. #26
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    I see, OK...

  27. #27
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Strange, but this one works in my system;


    Please Login or Register  to view this content.
    Last edited by Haluk; 10-10-2022 at 03:25 PM.

  28. #28
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by Haluk View Post
    I read this page about the "Initialize Event" and didn't get how it's about this bug.
    I mean, as soon as it executes the "If obj.val" it must execute the Class_Initialize code.

  29. #29
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    No, it says that; assignment of the property value generates the Initialize event.

  30. #30
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by Haluk View Post
    Strange, but this one works in my system;
    Please Login or Register  to view this content.
    Immagine 2022-10-11 105400.jpg
    I've no luck with this variant too, as for screenshot.
    Also, I still didn't understand if you (or in general, at least 1 person other than me) has the bugged behavior with my original code.

    At this point my focus is to understand two things:
    - whether it's a sort of a corruption of my Excel environment (maybe an addin?) or a bug of my (1year 10monthes old) Excel version
    - (if a bug) the exact boundaries of the bug in order to make a clear rule in my mind about what I should avoid in future when coding in/for this Excel version (and older?), considering that all of my company of about 25 thousand people are using a similar version of mine: Excel for Microsoft 365 MSO (16.0.13127.21062) 64-bit.

  31. #31
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by Haluk View Post
    No, it says that; assignment of the property value generates the Initialize event.
    It says that it's the "use" of the object to fire it. The "assignment" sentence is only about the example:
    "The Initialize event isn't triggered by the declaration of a new object. It's not until the object is used for the first time that the Initialize event is called. For example, in the code fragment:
    [...]
    The assignment of the CustName property value generates the Initialize event"

    Anyway I see that my original code fires it:
    Attachment 800070

  32. #32
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Seems like I didn't explain it well enough, i will stop at this point. Good luck

  33. #33
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by Haluk View Post
    Seems like I didn't explain it well enough, i will stop at this point. Good luck
    Also, that page continues like this with another different example:

    "in the following code, the Set statement generates the Initialize event.

    Please Login or Register  to view this content.
    I "set" it inside the function.
    I think that you're trying to tell me that I should set it outside the function too but that doesn't make sense to me because:
    - outside the function (for the "If") I only need the string property return value, not the inner object
    - anyway, that would mean that the current Excel version would be bugged instead (since it works as I expect with my original code)

  34. #34
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by 6diegodiego9 View Post
    all of my company of about 25 thousand people are using a similar version of mine: Excel for Microsoft 365 MSO (16.0.13127.21062) 64-bit.
    What release channel are you on?

  35. #35
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    70

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    Quote Originally Posted by rorya View Post
    What release channel are you on?
    I believe "Semi-Annual Enterprise Channel"
    A Google search for the version numbers lead me to a date around 2021-january

  36. #36
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: If obj.val = "zzz" Then (and it's true even if "aaa" or "bbb"! ABSURD!!)

    I think I'd be enquiring of your IT team as to why you are so out of date. There have been quite a few security updates since then.

+ 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. How new version Formulas will worki n old excel version
    By Sekars in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-20-2021, 01:57 AM
  2. [SOLVED] Need to use formula to lookup most recent "Agent" by date 4 a list of customers over 2yrs
    By Miskondukt in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-09-2017, 04:26 PM
  3. Replies: 0
    Last Post: 01-09-2016, 02:02 PM
  4. Formulas not working in higher version, 2010 Version to 2013 version
    By thilag in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-19-2015, 09:09 PM
  5. Replies: 2
    Last Post: 04-11-2015, 12:44 AM
  6. Get code that works on excel version 2007 to work on version 2010
    By Agent1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-21-2014, 01:23 AM
  7. Replies: 3
    Last Post: 06-16-2005, 11:05 PM

Tags for this Thread

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