1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Constants before declaration

Discussion in 'Android Questions' started by davemorris, Aug 3, 2019.

  1. davemorris

    davemorris Member Licensed User

    Hi Guys
    Having an issue about constants used before declaration - l looking at the forum, I found a bug report from 2015
    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
  2. LucaMs

    LucaMs Expert Licensed User

    How do you use these constants? MyModule.MyConst should work.
  3. davemorris

    davemorris Member Licensed User

    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)
    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).
    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
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is not considered a bug. The declaration order is important.
  5. davemorris

    davemorris Member Licensed User

    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
  6. emexes

    emexes Well-Known Member Licensed User

    I tried doing the same thing with some code statements. Then when I ran a test on the software, it simply malfunctioned.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice