Limit scope of constants to .bi but enable use in subs

General FreeBASIC programming questions.
Post Reply
Tonigau
Posts: 36
Joined: Feb 25, 2021 20:19

Limit scope of constants to .bi but enable use in subs

Post by Tonigau »

I have a .bi file where I declare some constants, but I want to limit the scope of the const visibility to just the bi.
If I use...

Code: Select all

Scope
   Const CR_LF = Chr(13,10)
   Const DQ = Chr(34)
End scope
The subs/functions in bi can't see constants(variable not declared), but if I End Scope after sub/funct I get "Illegal inside a scope block".

The constants make code easier & more readable.

Thanks
fxm
Moderator
Posts: 12133
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Limit scope of constants to .bi but enable use in subs

Post by fxm »

To limit the scope of constants, you can use the '#define...#undef' sequence:

Code: Select all

#define CR_LF Chr(13,10)
#define DQ Chr(34)

' code section can use the constants defined above
' .....

#undef CR_LF
#undef DQ

' previous constants are no longer defined
' (and can even be redefined)
' .....
Tonigau
Posts: 36
Joined: Feb 25, 2021 20:19

Re: Limit scope of constants to .bi but enable use in subs

Post by Tonigau »

Works perfectly,
thanks
Post Reply