Menu

Declaring Variables - Force Explicit Declaration?

Help
mkstevo
2015-05-08
2015-05-18
  • mkstevo

    mkstevo - 2015-05-08

    Is there an option in GCB that would force variables to be explicitly declared before use? I ask as I have been confused for a few long hours chasing a mistake of (admittedly) my own making.

    Having declared a constant:

    #Define CountDownTime 200000
    Dim CountDownValue as Long

    I made the mistake of referring to it (much) later in my code as:

    Let CountDownValue=CountDown_Time

    My code then continued:

    If CountDownValue > 1 Then
    Let CountDownValue=CountDownValue-1
    If CountDownValue=0 Then
    ;Do Count Down finished stuff here
    End If
    EndIf

    Of course my countdown never started as instead of being initialised to a value of my constant CountDownTime (200,000) CountDownValue was instead initialised to the value of the newly created CountDown_Time (0).

    As I said, this took me a long, long time to spot.

    The Tree view offers a Variable view, but this only shows variables that have been declared using 'Dim', not variables automatically created at compile time, nor constant values declared using '#Define'.

    If there is an option to force explicit declaration of variables (with 'Dim') I would love to be told how to implement it. Alternatively if I could invoke an option to show all variables and constants in the tree view, I'd love to know how. If neither of these are current options, is there any chance that a kind person would take pity on an ageing coder and consider adding this to any 'wish list'?

    Many thanks to all involved for GCB, and I'm sorry that my first post is a request for assistance.

     
  • Anobium

    Anobium - 2015-05-08

    Sorry. Not at the moment.

    We have some limited functionality but it not robust and may cause many issues.

    And, do not worry.... it is good to ask.

    :-)

     
  • Peter Stone

    Peter Stone - 2015-05-11

    I have made this mistake on many occasions before.

    I have suggested that the compiler outputs a list of automatically declared variables to make this error easier to identify.
    As a short term workaround you can make a habit of inspecting the .lst output which identifies all variables both directly and automatically declared.

    Peter.

     
  • mkstevo

    mkstevo - 2015-05-18

    Thanks to you both for your kind replies. At least I know it isn't just me...

    It would be a help if automatically declared variables were listed in the tree view (or something similar). I do like your suggestion Peter of looking in the .lst file, I shall give that a look once I'm back at my (compiling) PC. I hope it shows constants too.

    And, again, thanks.

     

    Last edit: mkstevo 2015-05-18

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.