Option _Explicit Keyword(s) of day XXX:
#23
Hello mnrvovrfc

Quote:This explanation makes no sense. Could you clue us in on the role of the variables?
 
Perhaps I could have come up with a better algorythm to demonstrate how Option _Explicit seems to eliminate a local variable, you pretty well have to Dim Shared all your variables and make them global. If you run the code I provided without Option _Explicit you can see where the x variable, when only Dim'd (not Shared) will come up with the correct value exactly in the module where it has been Dim'd. You can count on any other use of a variable Dim'd in a different module to = 0. 

Quote:I don't know what you mean by "throwaway" variables, there is no programming language that supports such a thing.
Ya, it's the programming language of DimBasic. I generally think of single use variable like for a counter or a local variable as one which serves it purposes and can be discontinued as 'no longer material to the ultimate results of the program', as a throwaway. Its a very important key word in DimBasic. 

And Terry (The Best of the Best)
I was trying to create real local variables in my subroutines and Not pass any reference values. The point being a Dim'd value is local by it's nature. Option _Explicit tends to stop the creation of a local variable in a subroutine. I hope this example demonstrates that point 

Code: (Select All)
'Option _Explicit

Dim x
'Dim Shared x2
x = 1

Print x
Subx2

Sub Subx2
    Dim x2
    x2 = 100
    Print x2
End Sub
Here I have a local variable in the main module declared by a simple Dim x, and a second local variable in the subroutine also declared by a simple Dim. Because I have Option _Explicit commented out when you run the code the answers are correct, but if you uncomment Option _Explicit that x2=100 is problematic. You have to Dim Share it and comment out the Dim x2 in the subroutine. As you correctly point out, there is always passing the value by reference but to me, and considering what an expert I am in Basic coding, a variable relying on a reference value is no longer a "throwaway" variable. (ok Steve to use this definition in your Bible)

Option _Explicit has me making all variables global and the "throwaway" thrown away. The bonus is I now have very meaningful variable counters like

For NutsINtheJar = 1 to 1000Tonguerint "Place a Nut in the Jar": Next
Reply


Messages In This Thread
RE: Option _Explicit Keyword(s) of day XXX: - by Dimster - 06-09-2023, 06:44 PM



Users browsing this thread: 23 Guest(s)