Announcement

Collapse
No announcement yet.

Ubound

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

  • Ubound

    Just a quick question, gentlemen,

    i try to get the UBOUND of a given ARAY in a structure like this:

    [code]
    TYPE myStruct
    lArray(5) AS DWORD
    END TYPE
    [code]

    I use a pointer to acces the structure like:

    [code]
    Local ptmyStruct AS myStruct PTR
    [code]

    Now I want to get the UBOUND of lArray.

    Thanks
    Joerg
    Joerg Koehler

  • #2
    Perhaps something like this would work.

    Code:
    TYPE myStruct
       lArray(5) AS DWORD
    END TYPE
    
    FUNCTION PBMAIN()
       LOCAL ptmyStruct AS myStruct PTR
       LOCAL mStruct AS myStruct, arr() AS DWORD
       ptmyStruct = VARPTR(mStruct)
       DIM arr(LEN(@ptmyStruct)/4 - 1) AT ptmyStruct
       MSGBOX STR$(UBOUND(arr))
    END FUNCTION

    Comment


    • #3
      Joerg --

      UBOUND can't be used on arrays that are part of a TYPE, mostly because there is no need for it. Here's why...

      In a TYPE, you must hard-code the number of elements at compile-time. Once the program is compiled, it can't be changed. So you may as well hard-code the upper bound as well. For example:

      Code:
      %MAX_ELEMENT = 5
      
      TYPE myStruct
           lArray(%MAX_ELEMENT) AS DWORD
      END TYPE
      Then instead of using UBOUND(something) simply use the constant %MAX_ELEMENT.

      -- Eric
      "Not my circus, not my monkeys."

      Comment


      • #4
        Code:
        %MY_ARRAY_UBOUND =  number 
        
        TYPE myStruct
           lArray ( %MY_ARRAY_UBOUND) AS DWORD
        END TYPE
        ...
        MSGBOX "UBOUND OF MY ARRAY IS " & FORMAT$(%MY_ARRAY_UBOUND)
        BTW, LBOUND, UBOUND and ARRAY XXX functions may not be used against "arrays" defined inside UDTS, because they are actually NOT arrays, they are tables.

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

        Comment


        • #5
          You know, I almost ended my post with...

          P.S. Ladies and Gentlemen... Mr. Michael Mattias.

          "Not my circus, not my monkeys."

          Comment


          • #6
            @Eric

            Your solution is what i did in parallel althought i actually haven't had a glue why UBOUND failed.

            I can (and probaly have to live with that)

            Thank you guys for your explanations!

            Joerg
            Joerg Koehler

            Comment

            Working...
            X