Avoiding Circular References

Because constants can be defined in terms of other constants, you must be careful not to set up a circular reference between two or more constants. A circular reference occurs when you have two or more public constants that are defined in terms of each other, as in the following example.


' In Module 1:
Public Const conA = conB * 2

' In Module 2:
Public Const conB = conA / 2

Visual Basic generates an error when you attempt to run a macro that contains a circular reference. You cannot run the macro until you resolve the circular reference. To avoid creating a circular reference, restrict all your public constants to a single module or a small number of modules. This way, it will be easier for you to keep track of your constants and catch this kind of mistake.