As you guys probably know, a lot of the stuff I write, I write it in such a manner than I can use it inside a library later, if I want to. Here's a little epiphany that occurred to me today, that I thought I'd share, which other library builders might want to make use of:
'k is for the keyboard
'active is a return code for which menu we got the result from, in case someone makes multiple menus
' with the same options listed in the sub menus, such as PAINT -- Circle as one menu/submenu
' and then DRAW -- Circle as another menu/submenu.
' Both would just return "Circle" as our final choice, so we'd need to know which menu was active
' and where the command came from.
STATIC oldmouse
AS INTEGER 'the old status of our left mouse button (up or down) IF mb
= 0 THEN resetmb
= -1: mb
= _MOUSEBUTTON(1) 'shortcut key so I don't have to type _mousebutton(1) multiple times.
mb, mx, my are my usual names for simple variables for mousebutton, mousex, and mousey, to help me cut down on a lot of typing. The problem with using them in code which might be stripped out and tossed into a library is that I also often use them as DIM SHARED variables, which means the local sub values could end up corrupting the global values if I just automatically reread them...
So, my solution here is this one:
IF mb = 0 THEN resetmb = -1: mb = _MOUSEBUTTON(1) 'shortcut key so I don't have to type _mousebutton(1) multiple times.
IF mx = 0 THEN resetmx = -1: mx = _MOUSEX
IF my = 0 THEN resetmy = -1: my = _MOUSEY 'same here.
If they're global variables, they'll pass whatever value they have into the sub, and I won't bother to get them from our mouse functions. If they're not global variables, there won't be any value to pass, so since they default to 0, I'll get the current values...
Only IF they're global and 0 to begin with, can I have any conflict with using the names inside this sub...
...and that's easily resolved by checking the reset variable and then resetting them to 0 before I exit the sub, if I need to.
Now, I can safely use mb,mx,my inside my sub and not need to worry about if they're local or shared variables. As long as someone keeps mb, mx, my as representing the mouse buttons, and don't make them represent something else in their code (which I never do, as it's just habit for me to make them mouse, just as k is for keyboard, m is for mem, i and j are for loops...), it now no longer matters if they're shared or local. The SUB/FUNCTION is now prepared to deal with them either way. ;)
Anywho...
I just thought I'd share. I've been writing library code for a long time now, and this simple solution is the first time I've ever considered and thought of something like this, so I thought I'd go ahead and share the concept for others. If it's useful for you, GREAT! If not, then... MuHaHaHaHa! I wasted a precious 2 minutes of your life that you'll never get back after having read my ramblings! (Now, if I could only figure out how to add those 2 minutes to my own life span...) :P