Do you use conditional compilation arguments?

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,152
Just curios, I heard about conditional compilation arguments the other day and not quite sure when or how I would use it. Does anybody use this technique and in its basic form how would you use it?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
my limited understanding is that they are used to include or exclude bits of code which wont run under different OSs or versions of excel. i havent been in the position to need to use it, but i have seen it used when accessing the API to draw windows in xl97.
 
Upvote 0
You could use it, for example, to develop an application earlybound (for IntelliSense), and then switch to latebound for deployment:

Code:
[FONT=Consolas][COLOR=#595959]#Const EarlyBound = False[/COLOR][/FONT]
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
[FONT=Consolas][COLOR=#595959]Function WriteUTF8(sText As String, sFile As String) As Boolean[/COLOR][/FONT]
[COLOR=#595959][FONT=Consolas]  ' Returns True if sText saved successfully as UTF-8 in sFile[/FONT][/COLOR]
<o:p></o:p>
[FONT=Consolas][COLOR=#595959]   On Error GoTo Oops[/COLOR][/FONT]
<o:p></o:p>
[COLOR=#595959][FONT=Consolas]  #If EarlyBound Then[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]      ' Requires a reference to Microsoft ActiveX Data Objects[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]      With New ADODB.Stream[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]  #Else[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]      ' No reference required[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]      Const adTypeText As Long = 2[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]      Const adSaveCreateOverWrite As Long = 2[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]      With CreateObject("ADODB.Stream")[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]  #End If[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]          .Type = adTypeText[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]          .Charset = "utf-8"[/FONT][/COLOR]
 
Upvote 0
I dunno where the HTML came from -- it's not mine.
 
Upvote 0
I've also seen it used when codes across versions are written.

For example

Code:
#If VBA6 Then
    'Do Something
#Else
    'Do Something
#End If
 
Upvote 0
I have used them in the past in a language called DataFlex where we used them to include/exclude client specific behaviour.

The problem with them is that you can't simply distribute the compiled code to all your users; you have to compile a number of times with different compile options.

(this also means that you should TEST with every set of compile options...)

Obiron
 
Upvote 0
It can be handy if you need to develop for Mac and Windows.
 
Upvote 0
I've used it in the past to include Debug.Print statements during development then exclude them for live releases.
 
Upvote 0
Thanks to all. Well it seems at this point I may not have much use for this technique, but you never know, maybe one day.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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