Qbasicnews.com

Full Version: Question about constants
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
never worked with QB so my question is:

The constants in FB have no prefix, so how do you distinguish that a name for a user constant is already taken by an operating system include file?
Will the constant value be overwritten?

Windows has thousends of constants...

In other Basic's there is a prefix like $ or # etc.
XBasic even distinguishes between system constants (constants in os include files) and user constants:
system constants : $$IAMASYSTEMCONSTANT
user constants : $IAMAUSERCONSTANT

How do you guy's manage it...

Victor, Is it possible to get the prefix stuff into the compiler?
Just a question...

Take care everybody...
In QB as well as FB, constants are preceeded with Const:
Code:
Const ThisIsAConstant = 9
but there is no real way to know if ThisIsAConstant is a variable, constant, function, etc. So, usually coders tend to give them some kind of distinguishing feature. The best way to do it is to use all capital letters to define it:
Code:
Const THISISACONSTANT = 9
Of course, FB lets us use underscores (which QB4.5 doesn't, to my knowledge), so you get to do stuff like:
Code:
Const THIS_IS_A_CONSTANT = 9
That's the way BASIC usually works anyways. Deviations from that aren't very BASIC-like.

The same name cannot be assigned twice. If you try it, you get this error:
Quote:error 4: Duplicated definition
so if you create a constant the same as a constant in one of your includes, you'll know that the name is already taken. And of course, since FB is (like any real BASIC) case-insensitive regarding variables, you cannot create mutliple variables with the same name but different cases, so there's no chance of messing up there either. Big Grin

FB isn't XBasic, and never will be, just like FB isn't C and never will be. Big Grin Prefix stuff like this, imo, is an overcomplexity that isn't required. If you set forth your own conventions, you should be able to tell the difference between a constant and a variable. Smile
thanks