Announcement

Collapse
No announcement yet.

User's Manual

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • User's Manual

    In the User's Manual and Reference Guide it does not mention that one cannot dimension an array using an equate,e.g.,

    %ArraySize = 1000

    DIM G(MAX,2) AS INTEGER

    DIM G(3,ArraySize)

    Is the above a syntax error or an idiosyncrasy of powerbasic?

    Also, neither manual mentions the limitations for using PUBLIC in PBUs. In quickbasic, one can encapsulate modules by using named common. Each module can have its own named common and also reference named common in other modules. For example:

    MAIN
    DEFINT A - Z

    COMMON /A.s/A1, A2, A3, A4
    COMMON /B.s/B1, B2, B3
    COMMON /C.s/C1, C2, C3

    END

    MODULE 1

    DEFINT A - Z
    COMMON SHARED /A.s/ A1, A2, A3, A4
    COMMON SHARED /D.s/ D1, D2, D3, D4

    END
    MODULE 2

    COMMON SHARED /B.s/ B1, B2, B3
    COMMON SHARED /D.s/ D1, D2, D3, D4
    COMMON SHARED /E.s/ E1, E2, E3, E4

    Can the same type of thing be done using PUBLIC in the PBUs?
    Walt Decker

  • #2
    DIM G(3,%ArraySize) AS INTEGER works on my PB/DOS 3.5 system. (Don't forget the leading percent sign on %ArraySize)

    You many have a conflict using both DIM G(MAX,3) and DIM G(3,%ArraySize), as the DIM(MAX,MIN,dimcount) format is usually reserved to handle situations where an array is passed or otherwise used in a module in which it is not allocated.




    ------------------
    Michael Mattias
    Racine WI USA
    [email protected]
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Hmm.

      So one can have both an equate and a variable with the same name.
      Strange.

      What about PUBLIC and PBUs referenced above?

      If one wants to use an equate referenced in the main module in a PBU must it also be referenced in the PBU? In quickbasic, constants (equates) referenced in main must also be referenced in
      in the linked modules.



      ------------------
      Walt Decker

      Comment


      • #4
        I do not use PUBLIC variables much at all; I much prefer my PBU files to contain procedures which pass any needed arrays as parameters.

        Unless I am mistaken, you can use a PUBLIC to share data by address across multiple code modules thus...

        Code:
        ' Main.Bas
          DIM X(10) AS INTEGER
          PUBLIC X() 
        ' Pbu.bas
          DIM Z(MAX,1) AS INTEGER
          PUBLIC Z()
        In this code, Z() in the unit is the same as X() in the main (it is the first entry in the list of PUBLICs).

        PUBLIC in a UNIT is useless without a SHARED somewhere in that unit.

        AS far as equates, an equate only exists at compile time; separately compiled modules each require the equate definition available at its compile time. Usually you would use an include file...

        $INCLUDE "Myequate.BI"

        in both the main and the unit source.

        MCM

        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Equates are not variables. Equates are named constants that are
          replaced with their constant value at compile time. You must ALWAYS
          precede an equate with a percent sign so that PowerBASIC can tell
          the difference between an equate and a variable, which explains why
          you can have an equate and a variable of the same name. Equates in
          units are seperate from equates in main, so you must define your
          equates in each and every unit in which they appear. The best way
          around that is to create a file of common equates, and then $INCLUDE
          that file in each unit that requires those equates.

          You can reference PUBLIC variables across multiple modules. Just
          declare the variable PUBLIC in each unit in which it is to be shared
          (be sure to declare them PUBLIC in main also), and all those units
          will be referencing the same variable. Declaring a variable PUBLIC
          automatically declares it SHARED, so that is not required. Also,
          the names of PUBLIC variables are signifigant. PUBLIC variables of
          different names are DIFFERENT variables, regardless of their order
          in the list of PUBLIC declarations in each unit. PUBLIC variables
          are truly global, and so must be referenced by their specific names.

          The use of DIM to declare an array, as in:
          DIM G(MAX,2) AS INTEGER

          merely declares the array, and does not actually dimension it. It
          is perfectly legal to have both a declare for an array and an actual
          DIMension statement for that array in the same unit, or in main.
          This allows you to store all your array declarations in a file
          which can then be $INCLUDEd in all units that need them, and in
          main, without the declarations clashing with your DIM statements.
          You can then do the actual DIMming of the arrays anywhere, in either
          main, or in any of those units.

          Hope that helps.

          ------------------

          Comment

          Working...
          X