D davemorris Active Member Licensed User Longtime User Aug 3, 2019 #1 Hi Guys Having an issue about constants used before declaration - l looking at the forum, I found a bug report from 2015 https://www.b4x.com/android/forum/t...onstants-referenced-before-declaration.54185/ describing a similar problem (mine is in a code module and I have used publics). My question is Is this is a bug or not - or has it returned. My general experience with modern compilers, is the order of declaration is normally not important, should this be the case with B4A? Kind regards Dave
Hi Guys Having an issue about constants used before declaration - l looking at the forum, I found a bug report from 2015 https://www.b4x.com/android/forum/t...onstants-referenced-before-declaration.54185/ describing a similar problem (mine is in a code module and I have used publics). My question is Is this is a bug or not - or has it returned. My general experience with modern compilers, is the order of declaration is normally not important, should this be the case with B4A? Kind regards Dave
LucaMs Expert Licensed User Longtime User Aug 3, 2019 #2 davemorris said: (mine is in a code module and I have used publics Click to expand... How do you use these constants? MyModule.MyConst should work. Upvote 0
davemorris said: (mine is in a code module and I have used publics Click to expand... How do you use these constants? MyModule.MyConst should work.
D davemorris Active Member Licensed User Longtime User Aug 3, 2019 #3 Hi, Thanks for the response Question did you read the original bug - it does sum-up the problem However, in my case I created a code module (lets called it myModule) Code: Copy Sub Process_Globals Public constant X1 as string = "First string" & X2 Public constant X2 as string = "Second string" Public constant X3 as string = X1 & X2 Then a separate class/activity used these constants (lets call it myClass). Code: Copy Private xxx as string = myModule.X1 ' xxx = "First string" ' **** the second half is missing (X2 defined after X1) Private yyy as string = myModule.X3 ' yyy = "First stringSecond string" ' ** X3 was defined after X2 therefore it is correct! As you can see the order of definition appears to by important for B4A. Having said all that, I may have made a error in my code and have to "eat my works!" Kind regards Dave Upvote 0
Hi, Thanks for the response Question did you read the original bug - it does sum-up the problem However, in my case I created a code module (lets called it myModule) Code: Copy Sub Process_Globals Public constant X1 as string = "First string" & X2 Public constant X2 as string = "Second string" Public constant X3 as string = X1 & X2 Then a separate class/activity used these constants (lets call it myClass). Code: Copy Private xxx as string = myModule.X1 ' xxx = "First string" ' **** the second half is missing (X2 defined after X1) Private yyy as string = myModule.X3 ' yyy = "First stringSecond string" ' ** X3 was defined after X2 therefore it is correct! As you can see the order of definition appears to by important for B4A. Having said all that, I may have made a error in my code and have to "eat my works!" Kind regards Dave
Erel B4X founder Staff member Licensed User Longtime User Aug 4, 2019 #4 It is not considered a bug. The declaration order is important. Upvote 0
D davemorris Active Member Licensed User Longtime User Aug 5, 2019 #5 Hi Erel OK I accept you have chosen to make the order of constant declaration important (although it don't appear to matter with subroutines). But, not reporting a problem is bad as the programmer is unaware of the situation. In my case I simply decided to rearrange some public constants in a code module into alphabetical order. Then when I ran a test on the software, it simply malfunctioned - very easy to trace the problem. However without a warning, this type of issue could cause hidden hard to find faults. Kind regards Dave Upvote 0
Hi Erel OK I accept you have chosen to make the order of constant declaration important (although it don't appear to matter with subroutines). But, not reporting a problem is bad as the programmer is unaware of the situation. In my case I simply decided to rearrange some public constants in a code module into alphabetical order. Then when I ran a test on the software, it simply malfunctioned - very easy to trace the problem. However without a warning, this type of issue could cause hidden hard to find faults. Kind regards Dave