Announcement

Collapse
No announcement yet.

Semantics and Other Questions

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

  • Semantics and Other Questions

    1. Why does this code work:

    FUNCTION SomeFunc(BYVAL A, BYVAL B) AS DWORD
    END FUNCTION

    while this code does not:

    SUB SomeSub(BYVAL A, BYVAL B) AS DWORD
    END SUB

    2. Since the FUNCTION semantic works above, how would one go about making it PUBLIC since PB seems to accept only one argument on the header line?

    3. UDTs and UNIONS

    I understand that UNION makes a UDT more flexible, but I don't understand how, ie, the semantics set up to allow the user to decided for himself the type or style of data he wants to enter. The PB manual is very skimpy on this subject (along with a number of other things).

    4. How does one go about accessing the PB code archives? There have been several posts that mention them, but so far, I have not been able to find them.

    Thanks
    Walt Decker

  • #2
    The SUB line doesn't work because a SUB cannot return a value, while a FUNCTION can. That's what the AS DWORD part is... for a FUNCTION, it means it returns a DWORD ... so you would call it like

    Code:
    MyDword??? = SomeFunc(a,b)

    To make a function public, it's like this:

    Code:
    FUNCTION SomeFunc(BYVAL A, BYVAL B) PUBLIC AS DWORD
    END FUNCTION

    A UNION is similar to a TYPE, except that each member of a UNION overlaps the other...each member starts at the same location in memory. Ex:

    Code:
    UNION Test
      a AS STRING * 2
      b AS STRING * 3
      c AS STRING * 1
    END UNION
    The length of the above UNION is 3 bytes (the largest member of the union is 3 bytes).

    Code:
    DIM x AS Test
    x.b = "xyz"
    
    ? x.a    'would give 'xy'
    ? x.b    'would give 'xyz'
    ? x.c    'would give 'x'
    You can put any type of data in a UNION that you can in a TYPE, including other UDTs

    As for the code archives... I can't remember but I believe they are at ftp.powerbasic.com in the pub/pbdos directory.


    HTH,
    Jason



    [This message has been edited by Jason McCarver (edited February 15, 2000).]

    Comment

    Working...
    X