Vba Rowdifferences

Microsoft Excel

Comic Sans is a bit inlormaJ. Proceed?

Yes }


... r


The next time the macro is executed, the variable NotFirstTime will be True, and so the If condition:

If NotFirstTime = False Then will be False and the MsgBox function will not be executed. Instead, the Else code will execute. This code just changes the font, without bothering the user with a message box.

Static variables are not used very often, but they can be quite useful at times.

It may have occurred to you that we could accomplish the same effect by using a module-level private variable to keep a record of whether or not the macro has been called, instead of a static local variable. However, it is considered better programming style to use the most restrictive scope possible which, in this case, is a local variable with an "extended" lifetime. This helps prevent accidental alteration of the variable in other portions of the code. (Remember that this code may be part of a much larger code module, with a lot of things going on. It is better to hide the NotFirstTime variable from this other code.)

0 0

Post a comment