Announcement

Collapse
No announcement yet.

PUBLIC TYPEs

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

  • PUBLIC TYPEs

    Hello everyone

    I've just started with PB 3.5, moving from Microsoft's Basic 7.1
    I have a large program, with multiple modules (units).
    Is it possible to share user defined variables between units and the main program?

    I mean something like:

    in Main:

    TYPE TipVar
    Int1 AS INTEGER
    Arr(12) AS LONG
    END TYPE
    DIM RegVar AS TipVar
    PUBLIC RegVar
    ...

    in unit:

    EXTERNAL RegVar
    ?RegVar.Arr(2)
    ...

    Thanks


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

  • #2
    Clarification:

    I know I can pass the user-defined variable as a parameter to any SUB in the unit, but I want to respect to the maximum the original QB code, and I don't want to pass the variable to every SUB in the unit, so I want to share it using PUBLIC and EXTERNAL.

    Thanks


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

    Comment


    • #3
      Absolutely, although you'll have to include the UDT definition in the UNIT code too. The best way is to put the TYPE/END TYPE statement block into a separate source file, and $INCLUDE it into each compilable source file.

      Essentially, you use PUBLIC in your main code; and you can use either PUBLIC or EXTERNAL in your UNIT code.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        OK,Lance; thanks.

        I had tried this but I didn't DIM the UDT in the unit (I just declared the TYPE), and the compiler raised an unresolved external; now it runs OK.


        ------------------
        Pere

        Comment

        Working...
        X