Active Forums => Programs => Topic started by: SMcNeill on December 23, 2019, 01:31:05 am
Title: Useful CONSTs (and such)
Post by: SMcNeill on December 23, 2019, 01:31:05 am
For a long time now, I've been meaning to work up a nice list of CONSTs which I feel should be assembled into a library for ease of inserting into a program. Ages ago, I did one for a lot of the 32-bit color constants, and a ton of people have taken advantage of those (and I've imported them to become native to QB64 itself with the new $COLOR:32 command which is in the Developer builds and will be available for everyone else when v1.4 is released later), but I've always felt that there were a lot of other little pieces of constant information that I had to keep looking up in the wiki over and over, that I really shouldn't have to...
Thus, I'm taking a few moments out of my menu creation project to step back and start on a useful CONST library. Feel free to assemble your own list of CONST values, and I'll add them all into this one library so people can import them into QB64 and pick and choose what parts they need from it via the $IF precompiler options.
As the library expands, the usage would be as simple as to save the above in a library file, toss it into your code, and place the following statement in front of its declaration:
No more would I need to constantly dig up the values to the limits for those various variable types. They'd always be just a simple to remember keyword away from easy access. :)
Other CONSTs will be coming and adding to the library as I work them up over the next few days. Use what you like, and feel free to add your own list of what you consider essential so that others can make use of the values as well easily.
Title: Re: Useful CONSTs
Post by: SMcNeill on December 23, 2019, 02:28:51 am
Added the Keycodes for _KEYHIT/_KEYDOWN, as I can never remember any of those and always have to look them up.
Again, usage is to:
1) Make the file a library file so you can include it in your code. 2) Place $LET KEYCODES = TRUE before the $INCLUDE statement. 3) Make use of the new CONST values.
One thing to note: QB64 doesn't distinguish between lowercase and uppercase variable names, so I don't have a Key_A_lowercase and a Key_A_uppercase defined. Instead, I defined a simple Key_UpperCase and Key_LowerCase set of CONSTs...
If you need to check for a value, simply check for the Key + Uppercase (or + Lowercase as desired):
SELECT CASE _KEYHIT CASE Key_A, Key_A + Key_LowerCase '(Or Key_LC if we want to reduce typing) END SELECT
Now I don't need to look up Key_Left, or Key_Right... It's just a simple matter of include the library and use the CONST names to remember them. :)
I don't think there's any codes wrong, or missing, but if there is and you guys notice them, kindly point them out to me and I'll correct them ASAP.
Title: Re: Useful CONSTs
Post by: SMcNeill on December 23, 2019, 02:38:49 am
Consolidated and added the color constant values into this list as well. Use is the same as above, but you need to specify which values you want to make use of
$LET COLOR = 32 will use 32-bit color values. $LET COLOR = 256 will use 256 color values. $LET COLOR = 0 will use SCREEN 0 color values.
Also added the CodePage DATA into this collection as well. Take the codepage you want, and set it TRUE with a $LET statement like above, and then RESTORE the data before making use of it, like below:
'Your program, until it gets to the MAPUNICODE section, and then RESTORE CodePage1258 And if you look, when you copy/paste the file into your IDE there's a lot of grayed out code in it. Since all this is being included and excluded via the precompiler (those $LET statements), you only add what you want to, to your programs. The rest is grayed out, skipped over, and as far as QB64 is concerned, it doesn't exist at all.... No EXE bloat, no increased program size, no unused data just sitting and taking up space.
Only when you enable what you want, does it actually become an active part of your program.