06-03-2023, 01:29 PM
1st I apologize to NasaCow, hope the discussion on Option _Explicit may help with the search for/correction of the error you were looking for help on.
2nd ... the issue/learning lesson, for me in this thread is Dimensioned variables v's UnDimensioned variables. In particular a control variable. I have often seen the use of "i" or "j" or "x" being used in many books on Qbasic where these control variables are not Dimmed. They appear to be throw away variables in terms of their use is not material to math formulas or capture of a results of a process. They can be used over and over again as a control variable because their type is defined by default and their value is clearly defined in a range (ie 1 to 10). The only time I will Dim a control variable like "x" is if I need it to carry over into a subroutine or back to the main module.
The Dimming of a control variable, in my experience just added to multiple lines of Dim and Dim Shared in a large program. Plus it doesn't help with the ending value , or limiting the control range. For example
In each case x and y finished outside of the control range, so I have to be careful when I do Dim x or y to use in another sub or function.
Not sure I see the value in Option _Explicit for control variables, nor how Dimensioning all control variables is a "Best Practice" but this old dog is definitely learning new tricks by trial and error especially when some masterfully programmers are highlighting the new trick.
2nd ... the issue/learning lesson, for me in this thread is Dimensioned variables v's UnDimensioned variables. In particular a control variable. I have often seen the use of "i" or "j" or "x" being used in many books on Qbasic where these control variables are not Dimmed. They appear to be throw away variables in terms of their use is not material to math formulas or capture of a results of a process. They can be used over and over again as a control variable because their type is defined by default and their value is clearly defined in a range (ie 1 to 10). The only time I will Dim a control variable like "x" is if I need it to carry over into a subroutine or back to the main module.
The Dimming of a control variable, in my experience just added to multiple lines of Dim and Dim Shared in a large program. Plus it doesn't help with the ending value , or limiting the control range. For example
Code: (Select All)
Dim Shared y(1 To 10)
Dim x
For x = 1 To 10
Print "Hello World"
Next
Print
Print x
Print
Print
For y = 1 To 10
Print "Hello back at ya"
Next
Print
Print y
In each case x and y finished outside of the control range, so I have to be careful when I do Dim x or y to use in another sub or function.
Not sure I see the value in Option _Explicit for control variables, nor how Dimensioning all control variables is a "Best Practice" but this old dog is definitely learning new tricks by trial and error especially when some masterfully programmers are highlighting the new trick.