Guys, I think some of you need a lesson in CONST vs unchanging VARIABLE.
A constant is a name given to a literal value. This value is one thing, one thing only, and will forever be that that one thing. You determine what that thing is BEFORE compiling the code, use the name in your code, and that LITERAL VALUE is placed into the code and compiled. We use CONST as programmers as it's easier than remembering set values.
Let me toss some values:
Byte_Limit = 2 ^ 7 - 1
Integer_Limit = 2 ^ 15 - 1
Long_Limit = 2 ^ 31 - 1
Integer64_Limit = 2 ^ 63 -1
Now, I can remember that byte's limit is 127 (or 2 ^ 7 -1), so I can swap those easily back and forth in my programs, but somebody tell me what the integer64 limit is. Go on. Off the top of your head, recite that value with 100% certainty. It *NEVER* changes. It's *ALWAYS* the same value. But WHAT is that value? It's a mighty big damn number. Do you have every digit memorized perfectly? Did you type every digit perfectly?
So instead of using the value directly, or even worse, using the unchanging formula above, we just use the CONST value as we have defined them in our code. The QB64PE compiler then sees that CONST, and as it translates your BASIC to C code, it substitutes that LITERAL calculated value directly for the CONST.
Code like: PRINT Byte_Limit
Becomes compiled as: PRINT 127
The compiler sees the LITERAL value; we see the CONST value for ease on our own understanding and usage.
Now, a program that starts up and runs once each day of the week might have code that determines:
TODAY = DayOfWeek
Now, all day long, like Charlie's example, this doesn't change. The program is set on a timed task. It runs from 8AM when your business starts up, shuts down at 10PM when your business closes at night. It's an UNCHANGING VARIABLE.
This is *NOT* a constant. It's not some literal in the code. You can't just say:
TODAY = "MONDAY" and then have it right all seven days of the week. You're getting the date, determining the day of the week, and storing it at runtime. It's not ALWAYS the same. You want it to change every day; you can't substitute a LITERAL unchanging value in its place and keep it valid, ergo it CAN NOT be a CONST.
And the same with Unseen's original idea.
CONST DW = _DesktopWidth
_DesktopWidth is a function that returns a value when its called. That function can be variable in its results. If you want it to be CONST, then what you want is:
CONST DW = 1920
See? A LITERAL, neverchanging value.
With CONST DW = _DESKTOPWIDTH, you could conceivably get the desktop resolution at compile time, make an EXE, and then have the literal value of your screen width stored in that compiled EXE forever.... Of course, if you buy a bigger monitor, it won't change or scale. If you move the EXE to a different machine, it won't change or scale. If you change resolution on your monitor, it won't change or scale.
You have.... defeated the whole purpose of that command being a function. It doesn't set that value at RUN TIME. It sets it at COMPILE TIME. If that's what you want, why don't you just right click on your desktop, hit DISPLAY SETTINGS when the popup appears, see what your values are, and then set them yourself?
CONST DW = 1920, DH = 1200
Presto! Permanent CONST values which will always be set in stone to match your screen when you wrote it.
To consider the idea in another perspective, it would be the exact same as:
CONST Today$ = DATE$
So your Today is going to be forever locked as the date you compiled, never changing, never really being Today... It'll just be "10/26/2025" forever. (As that's the day I wrote this post. Tomorrow, it won't change to update to "10/27/2025" and when folks read this a month from now, it won't match their day either.)
A variable you set one time and never change is NOT a constant.
A constant is a verbal descriptor of a LITERAL value.
One = 1
Two = 2
Three = 3
If your program is going to be:
SELECT CASE DayOfWeek
CASE "Monday": One = 1
CASE "Tuesday": One = 123
CASE "Weddingsday": One = 3.14157
END SELECT
Then that's NOT a CONST.
PI isn't 3.14159 on some days and 9.8763 on others. It's a literal, never changing value. We type PI because it's easier than typing 3.141592654....
See the difference in the two?
A CONST is a literal value, substituted in your code at compile time and only used for the programmer's benefit.
An unchanging variable is something you set once and then simply never alter the value of again inside your program.
It really is that simple of a distinction, but that's a pretty damn important distinction to make.
A constant is a name given to a literal value. This value is one thing, one thing only, and will forever be that that one thing. You determine what that thing is BEFORE compiling the code, use the name in your code, and that LITERAL VALUE is placed into the code and compiled. We use CONST as programmers as it's easier than remembering set values.
Let me toss some values:
Byte_Limit = 2 ^ 7 - 1
Integer_Limit = 2 ^ 15 - 1
Long_Limit = 2 ^ 31 - 1
Integer64_Limit = 2 ^ 63 -1
Now, I can remember that byte's limit is 127 (or 2 ^ 7 -1), so I can swap those easily back and forth in my programs, but somebody tell me what the integer64 limit is. Go on. Off the top of your head, recite that value with 100% certainty. It *NEVER* changes. It's *ALWAYS* the same value. But WHAT is that value? It's a mighty big damn number. Do you have every digit memorized perfectly? Did you type every digit perfectly?
So instead of using the value directly, or even worse, using the unchanging formula above, we just use the CONST value as we have defined them in our code. The QB64PE compiler then sees that CONST, and as it translates your BASIC to C code, it substitutes that LITERAL calculated value directly for the CONST.
Code like: PRINT Byte_Limit
Becomes compiled as: PRINT 127
The compiler sees the LITERAL value; we see the CONST value for ease on our own understanding and usage.
Now, a program that starts up and runs once each day of the week might have code that determines:
TODAY = DayOfWeek
Now, all day long, like Charlie's example, this doesn't change. The program is set on a timed task. It runs from 8AM when your business starts up, shuts down at 10PM when your business closes at night. It's an UNCHANGING VARIABLE.
This is *NOT* a constant. It's not some literal in the code. You can't just say:
TODAY = "MONDAY" and then have it right all seven days of the week. You're getting the date, determining the day of the week, and storing it at runtime. It's not ALWAYS the same. You want it to change every day; you can't substitute a LITERAL unchanging value in its place and keep it valid, ergo it CAN NOT be a CONST.
And the same with Unseen's original idea.
CONST DW = _DesktopWidth
_DesktopWidth is a function that returns a value when its called. That function can be variable in its results. If you want it to be CONST, then what you want is:
CONST DW = 1920
See? A LITERAL, neverchanging value.
With CONST DW = _DESKTOPWIDTH, you could conceivably get the desktop resolution at compile time, make an EXE, and then have the literal value of your screen width stored in that compiled EXE forever.... Of course, if you buy a bigger monitor, it won't change or scale. If you move the EXE to a different machine, it won't change or scale. If you change resolution on your monitor, it won't change or scale.
You have.... defeated the whole purpose of that command being a function. It doesn't set that value at RUN TIME. It sets it at COMPILE TIME. If that's what you want, why don't you just right click on your desktop, hit DISPLAY SETTINGS when the popup appears, see what your values are, and then set them yourself?
CONST DW = 1920, DH = 1200
Presto! Permanent CONST values which will always be set in stone to match your screen when you wrote it.
To consider the idea in another perspective, it would be the exact same as:
CONST Today$ = DATE$
So your Today is going to be forever locked as the date you compiled, never changing, never really being Today... It'll just be "10/26/2025" forever. (As that's the day I wrote this post. Tomorrow, it won't change to update to "10/27/2025" and when folks read this a month from now, it won't match their day either.)
A variable you set one time and never change is NOT a constant.
A constant is a verbal descriptor of a LITERAL value.
One = 1
Two = 2
Three = 3
If your program is going to be:
SELECT CASE DayOfWeek
CASE "Monday": One = 1
CASE "Tuesday": One = 123
CASE "Weddingsday": One = 3.14157
END SELECT
Then that's NOT a CONST.
PI isn't 3.14159 on some days and 9.8763 on others. It's a literal, never changing value. We type PI because it's easier than typing 3.141592654....
See the difference in the two?
A CONST is a literal value, substituted in your code at compile time and only used for the programmer's benefit.
An unchanging variable is something you set once and then simply never alter the value of again inside your program.
It really is that simple of a distinction, but that's a pretty damn important distinction to make.


