none
Set boolean property as what it is -> Crash RRS feed

  • Question

  • When I set a boolean property to what it already is, Excel throws an error. Is there any clear reason for this and can I avoid it by any other way than first checking the state? Examples of this are enableevents, calculation and worksheet.visible.

    Wednesday, March 5, 2014 10:20 AM

All replies

  • Hello KilpAr,

    Could you please be more specific? What Excel version do you have installed on the PC? When and where do you try to set these properties? 

    Wednesday, March 5, 2014 10:52 AM
  • The Excel version is anything between 2007 and 2013 (has to work in each). The development machine has Excel 2007, 32-bit. I try to use these in multiple places, for example in a form, I first hide all the sheets and then display the ones user selected. If I do this, the code for hiding a hidden sheet throws an error, while, of course, the correct behavior would be that program would see "oh, ok, it is already -> do nothing".

    Wednesday, March 5, 2014 12:05 PM
  • The correct behavior is not set the property anew if it is already set to the proper value. Don't you think so?

    Anyway, I'll try to reproduce the issue in my PC with Office 2013 SP1 installed and let you know my results.

    Wednesday, March 5, 2014 1:33 PM
  • Yeah, I agree, but if setting is forbidden when already set it triples the amount of code. For example, if we go with variables (which are not the problem, but illustrates the idea), you can do like

    bSomething = true

    without caring a single bit (literally) what the bSomething was in the first place

    Now, if we go to "not set the property anew if it is already set to the proper value" like you said, it means we need to use everywhere

    if bSomething <> bWantedState then

    bsomething  = bWantedState

    endif

    which, obviously, has two lines of extra code plus an extra operation (the comparison).

    Wednesday, March 5, 2014 1:52 PM
  • Hi KilpAr,

    If you know that you can get exceptions, there is no problems to add an additional line of code.

    Could you please show a piece of code which can help in reproducing the issue?

    Thursday, March 6, 2014 1:32 PM