08-12-2025, 06:10 PM
There's only one valid instance where I know you can change CONST, and that's as per the example here:
Note that FOO has a value of 123 in the main program. Then in the SUB we declare another CONST FOO and give it a value of 987. That second FOO is local in scope and *only* valid inside that SUB itself.
Now, as you mention, "I can't think of a practical example where such manipulation would make sense"...
There's only a single reason why I could see that one would want to make use of this feature of the language -- when creating a set of code to be used as an $INCLUDE library. You can set your CONST for use in your SUB/FUNCTIONs and not have conflicts with the user's other code which might reuse the same name as a const or variable. It makes your little subroutine more self-enclosed and independent, without affecting the main program as extensively.
If the above is the whole extent of my library code, it's going to be 100% self-contained and won't affect any variables or const which may exist inside any other program. It doesn't matter if you DIM SHARED foo, or if you have a different CONST foo in your main program. The CONST foo inside that SUB is local in scope, doesn't apply anywhere else, and is ONLY valid inside that sub.
It's a means to use CONST inside your libraries, without having to affect the rest of the code making use of those libraries.
Code: (Select All)
Const foo = 123
Print foo
Whatever
Print foo
Sub Whatever
Const foo = 987
Print foo
End Sub
Note that FOO has a value of 123 in the main program. Then in the SUB we declare another CONST FOO and give it a value of 987. That second FOO is local in scope and *only* valid inside that SUB itself.
Now, as you mention, "I can't think of a practical example where such manipulation would make sense"...
There's only a single reason why I could see that one would want to make use of this feature of the language -- when creating a set of code to be used as an $INCLUDE library. You can set your CONST for use in your SUB/FUNCTIONs and not have conflicts with the user's other code which might reuse the same name as a const or variable. It makes your little subroutine more self-enclosed and independent, without affecting the main program as extensively.
Code: (Select All)
Sub Whatever
Const foo = 987
Print foo
End Sub
If the above is the whole extent of my library code, it's going to be 100% self-contained and won't affect any variables or const which may exist inside any other program. It doesn't matter if you DIM SHARED foo, or if you have a different CONST foo in your main program. The CONST foo inside that SUB is local in scope, doesn't apply anywhere else, and is ONLY valid inside that sub.
It's a means to use CONST inside your libraries, without having to affect the rest of the code making use of those libraries.

