If we’re talking coding styles, here’s m general rules for DIM SHARED vs paramters:
1) If the sub/function (I’m just going to say SUB for both, from here out) needs to do something for multiple cases, I *always* use parameters. An example of this would be SUB Sort (array() AS LONG). Here, it doesn’t make sense to DIM SHARED array(), as I may have 5 or 6 different arrays I want to sort. What am I going to do? SUB Sort_array_a, SUB Sort_array_b, SUB Sort_array_c... That doesn’t make a lick of sense.
2) If the same variable is going to be used in multiple SUBs, I’ll DIM SHARED it. Once again, it just doesn’t make sense to me to: SUB Capitalize(text$), SUB StripCRLF(text$), SUB AddCHR10 (text$), SUB PrintOut (text$), SUB Blank (text$)... All these routines work with the same singular variable — why the heck isn’t it just DIM SHARED? Save the typing — prevent carpet tunneling!
3) If a variable is going to mainly be referenced without changing, I’ll DIM SHARED it. Fro example: DIM SHARED ScreenX, ScreenY. I might have one routine that checks if the user has resized the window, which sets my ScreenX/Y, but that’s not going to change anywhere else. Elsewhere it’s just read and used; not changed. Why not just DIM SHARE it?
4) Sub usage also affects things. If I’m just writing a SUB for internal use in a singular, specific program, then it doesn’t matter. As long as the proper data is interchanged from the main module and the SUB, it’s all good. If, however, I’m writing a SUB to pull out for my toolbox, or a library, then I want it to be as self-contained as possible. Parameter passing is preferred then over DIM SHARED. Why have to $INCLUDE two files, when one can do just as good?
And anytime not covered by these general rules, I tend to just go with whatever suits my taste at the moment. At the end of the day, the biggest concern is: Does the code work, or not? If it does, then all is good. If not, the SHARE or pass whatever is needed so it does. ;D