Posts: 2,020
Threads: 24
Joined: Jun 2002
Constants arent variables, it's shorthand that's tossed when your program is compiled.
CONST left = 75
CONST right = 77
if inp(&h60) = left then '...
which you compile, it changes to this:
if inp(&h60) = 75 then '...
etc. They have their purpose.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Posts: 440
Threads: 65
Joined: Sep 2001
That's right toonski. I didn't choose my words well I guess -- that happens often these days. :-?
I was thinking in 'variables' just to make my point about using variables & CONST together, like...
CONT a = "HELLO"
Shorthand is a good way to think of CONST. Heh...I guess everything in source code is 'shorthand' until it's compiled
- Dav
Posts: 729
Threads: 105
Joined: Feb 2003
I heard somewhere that it's a speed issue... CONSTs are faster or something like that.
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Posts: 3,368
Threads: 195
Joined: Jan 2003
yes, since CONST stuff is hardcoded bits while vars must be looked up from memory.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 2,771
Threads: 96
Joined: Oct 2003
wow thanks for the responses guys, I understand it now. Meg's C program snippet helps a lot, even if there isnt that much to understand :wink: Thanks!
Posts: 1,845
Threads: 44
Joined: Aug 2002
I'll just continue the thread...
CONST: faster than DIM or any other declaration and in C++/C a constant is replaced by its value by the preprocessor (AFAIK this is also done in QB).
CONST: can be used in an include file, a sequence of DIM SHARED's and Var = value's can't be used in an include file.
CONST: can be used throughout your whole project, DIM SHARED only works in the current module.
Some extra info