No announcement yet.

Where is the ubound for type arrays?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Where is the ubound for type arrays?

    Type MyType1

    Hello As Long

    End Type

    Type MyType2

    Hello2 As Long
    MT( 0 To 20, 0 To 60 ) As MyType1

    End Type

    Dim MyType As MyType2
    Msgbox Str$( Ubound ( MyType.MT() ) )

    I receive a period not allowed...

    I Would like to know the ubound of MT() and MT(2).
    And why can't i use : instead of To?

  • #2
    E.B. --

    Arrays in TYPEs have certain limitations -- you can't use ARRAY SORT, for example -- and this is apparently another one. My guess is that since arrays in TYPEs must have hard-coded dimensions (since you can never use variables in a TYPE definition) that the developers assumed that nobody would ever want to use UBOUND. It would be very inefficient.

    If you want your code to automatically "track" the size of the array as you change it during development, I'd recommend using equates. For example...

    %Dim1UBOUND = 20
    %Dim2UBOUND = 60
    TYPE MyType2
        Hello2 As Long
        MT( 0 To %Dim1UBOUND, 0 To %Dim2UBOUND) As MyType1
    ...and then you could use %Dim1UBOUND or %Dim2UBOUND instead of UBOUND in the rest of your code. It would be much, much more efficient than using UBOUND, even if UBOUND worked.

    -- Eric

    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>

    [This message has been edited by Eric Pearson (edited February 16, 2000).]
    "Not my circus, not my monkeys."


    • #3
      That's exactly how we 'solved' it.

      However, since thes kind of arrays are steady, why not SORT etc..?
      And Ubound was just a common practice for me, Now i need to know(type) this variable and it could differ per app (#app..)

      But ok, good for now.




      • #4
        I like to come back on my previous answer.

        Even MAT doesn't work on type arrays.

        Is there a little workaround for now?
        Like a pointer to the array and sort it etc.. ?




        • #5

          Actually I think that PowerBasic should rename 'Arrays' in UDT's as 'Tables' in the documentation.

          This would save a lot of confusion, as I tried using array-specific statements on UDT 'Arrays' and I couldn't figure out the problem until I asked on this forum.

          Kev G Peel
          KGP Software
          Bridgwater, UK.
          mailto:[email protected][email protected]</A>