Scope of Compiler Directive Constants

pingel

New Member
Joined
May 23, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I am trying to develop some level of module dependence check within my project.
I was thinking that I could add a compiler constant in the module I want to ensure was loaded, i.e.

#Const ModuleX_Loaded = True

And then, in the module that I want to ensure I only add code for if the required module is loaded, I could add the following code:

#If ModuleX_Loaded = True Then
.. some code to make use of the elements in ModuleX

#Else
.. some replacement code or some error code to identify the ModuleX is missing

#End If

What I find, though, is that the #If statement always evaluates to False, and I get the Else code executed.

Do you have any ideas - or specific information about the Scope of a compiler constant, which, according to Microsoft Learn, should be global?

-Jan
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Conditional compiler constants are local to their module.

Edit: I am referring to ones defined by #const. built in ones are global.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,134
Messages
6,123,237
Members
449,093
Latest member
Vincent Khandagale

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top