06-02-2023, 08:23 PM
(This post was last modified: 06-02-2023, 08:27 PM by Kernelpanic.)
(06-02-2023, 02:21 PM)bplus Wrote:(06-02-2023, 11:19 AM)Dimster Wrote: When I get a "Duplicate definition" error it's seems to always be related to my misuse of the CONST statement. Somewhere in my program I tried to change the variables value when it supposed to have been fixed.
Option _Explicit is not called for in this case, everything already has worked for your protection.
You declared a variable name to be constant and the IDE is telling you of your blunder of trying to use a Constant like a true variable.
Option _Explicit is just good programming practice, specially for large projects.
A const variable is just a normal variable. If it is misspelled, the following happens: In QuickBasic (Basic in general), a new variable is (was) initialized with 0 by default until it is assigned a value. That means every typing error leads to a new variable with the value 0.
Example of a typo for a const variable (calculate the circumference of a circle):
And this is how the result is correct: