Option _Explicit Keyword(s) of day XXX:
#11
@Dimster I understand what you're saying perfectly.  In fact, I tend to think the same way a lot of times:  Stupid OPTION _EXPLICIT!  Nothing is any more annoying than having to scroll back 500 lines of code to get back to the declaration area of your source/routine, just to add a little DIM x, y into the code to create a couple of simple loops.

I tend to enjoy programming in a constant flow, when the creative juices are all working properly.  My brain is quickly moving forward with:  Let's do this, and then this, and then onto this, and in the end we'll accomplish this!  Having to stop, back up, and then scroll to the beginning and add in a DIM statement interrupts that flow of indeas for me, makes me lose track of what the heck I was trying to accomplish, and takes me "out of the zone" for productive programming.  It's the same way when I tend to work on one of my novels -- I let the creative juices flow, write the whole thing uninterrupted, and on AFTERWARDS do I ever think about going back and editing and proofreading.  Once I get in the flow, I don't want to break that for anything -- much less just to DIM a temp variable!!

So what's the simple solution?  Add the following to the start of your code:

Code: (Select All)
DIM a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z

There ya go!  All simple variables explicitly defined -- whether you actually make use of them or not -- and ready to go anywhere in your code.  Option _Explicit won't complain over them not being defined, and I won't get any errors anymore when you use them.   Since you didn't define them as any specific type, they're going to be the same DEFAULT type as if you just added them into your code without that single line of definition.

FOR x = 1 TO 10    <-- Without any DIM statement in your code, x would default to be a SINGLE type.

FOR x = 1 TO 10    <-- With the DIM statement we used above, x would still default to be a SINGLE type, as we didn't specify it as anything different.

Add that one single line to start of your program (and/or subs/functions to keep it limited in scope) and then Option _Explicit won't complain over those temporary control variables.  

It's really not that much to add, while allowing for the useful error prevention that Option _Explicit can help add into your coding toolbox.  Wink
Reply


Messages In This Thread
RE: Option _Explicit Keyword(s) of day XXX: - by SMcNeill - 06-07-2023, 03:59 PM



Users browsing this thread: 21 Guest(s)