Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using CONST
#15
There's only one valid instance where I know you can change CONST, and that's as per the example here:

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.
Reply


Messages In This Thread
Using CONST - by Dimster - 08-02-2025, 04:57 PM
RE: Using CONST - by SMcNeill - 08-02-2025, 05:12 PM
RE: Using CONST - by Dimster - 08-03-2025, 03:24 PM
RE: Using CONST - by TempodiBasic - 08-03-2025, 11:14 PM
RE: Using CONST - by Pete - 08-04-2025, 01:03 AM
RE: Using CONST - by SMcNeill - 08-04-2025, 02:15 AM
RE: Using CONST - by Pete - 08-04-2025, 03:33 AM
RE: Using CONST - by SMcNeill - 08-04-2025, 05:35 AM
RE: Using CONST - by Kernelpanic - 08-04-2025, 04:00 PM
RE: Using CONST - by SMcNeill - 08-04-2025, 06:50 PM
RE: Using CONST - by Pete - 08-04-2025, 05:02 PM
RE: Using CONST - by hsiangch_ong - 08-04-2025, 05:09 PM
RE: Using CONST - by Pete - 08-04-2025, 05:15 PM
RE: Using CONST - by Kernelpanic - 08-12-2025, 05:36 PM
RE: Using CONST - by SMcNeill - 08-12-2025, 06:10 PM
RE: Using CONST - by Kernelpanic - 08-12-2025, 07:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using CONST & _RGB used together seem to error... Dav 12 706 12-12-2025, 12:29 AM
Last Post: Dav

Forum Jump:


Users browsing this thread: 1 Guest(s)