Menu

Variables

Help
2007-10-09
2024-04-11
  • Nobody/Anonymous

    Are all variables global? Can functions and subs have local variables?

     
    • Hugh Considine

      Hugh Considine - 2007-10-10

      All variables are global, and there are no local variables (as yet).

      One warning is that the type of a variable is local. For example, if a variable is defined inside a subroutine as a word, it will be a word in that sub and a byte everywhere else. If a variable is defined in the main program, its type will be global.

       
  • Fabrice Engel

    Fabrice Engel - 2024-04-08

    Hello Community,

    During my conversion from MikroBasic to GCBASIC, I figure out (after many hours :) of debugging ) that local variables are not working with same syntax as MB, or maybe like the information in this forum entry that local variables are not supported in GCBASIC

    Is this still the case? Are local variables to Subroutine no available today?

    Thank a lot for feedback

     
    • Anobium

      Anobium - 2024-04-09

      In GCBASIC all variables are global, and, non byte variables created in sub/function are constrained to the specific sub/function and would need to be redimensioned for use outside of the specific sub/function.

      The Help covers this well.

       
  • Fabrice Engel

    Fabrice Engel - 2024-04-09

    Thank Anobium, ok I have already adapted in the source code. I have not noticed in my previous converted projects, had no local variable inside :)
    Will now continu the code. As far I am not using delay in my code, the program run much faster that with MikroBasic, that I assume they use delays in the button libray. So I need to create longer loops to get similar results. I will keep you on track....

     
  • Fabrice Engel

    Fabrice Engel - 2024-04-09

    Another point that I just figured out, when you create a variable 16 bits (word) from combination of 2 eeprom memory addresses, you need to load low and high part separatly.

    This is what I already did with MikroBasic. But the point here, is that attention must be taken to load first the lower part an than the higher part. If you do it in opposite, the 16bits variable will be not correct. I took not attention in MB, maybe the compiler handle it correctly and it works all the time.

    In GCBASIC, you need to take care to do it in the right way.

    Example:

    EPRead (2, VariableEE) // Read in eeprom low value
    EPRead (1, VariableEE_H) // Read in eeprom high value

    Or did I made something wrong? Does a better practice exists?

    Thank a lot

     
    • Anobium

      Anobium - 2024-04-09

      Correct.

      If you add a subroutine based on the existing EPRread you could create you own EPRead ( address, Variable_WORD)plus the code to read the two parts of the Word variables then you would have same functionality.

       
      ❤️
      1
  • Fabrice Engel

    Fabrice Engel - 2024-04-11

    Dear Community, some news about my activities round code conversion MikroBasic to GCBASIC.

    The last issues I had were with variable types. Certainly both compilers handle differently variables types and declarations. Some variable type Byte in my code needed to be changed into Word. Was in relation what calculations and operations are made. I needed some time to figure out why the system is reacting differently or why so times and delays are differently.

    Now the system conversion is near to the end, I need to control how run all parts of the code...
    Thank again for all the support received here.

     

    Last edit: Fabrice Engel 2024-04-11

Log in to post a comment.