Shop OBEX P1 Docs P2 Docs Learn Events
Is there away to point to an Array — Parallax Forums

Is there away to point to an Array

SXleeSXlee Posts: 47
edited 2011-03-01 03:04 in General Discussion
Hi all
Is there away to point to an Array and get it's dimension(upper bound), so I can pass them to a sub/function.
Array_1       VAR  Byte(16) 
Array_2       VAR  Byte(14) 
Array_3       VAR  Byte(11) 
Array_4       VAR  Byte(16)
Like so
Sub MySub2
  FOR idx = 0 TO 3
   DealWith_Array ThisArray, UBound 
  Next i
EndSub

Sub DealWith_Array
  FOR idx = 0 TO UBound
   TheArray(i)=i
   .........
   .........
   .........
   .........
   .........
  Next i
EndSub

I'm doing it like this now, but it takes a lot of space.
Sub MySub1
  DealWithArray_1
  DealWithArray_2
  DealWithArray_3
  DealWithArray_4
EndSub


Sub DealWithArray_1
  FOR idx = 0 TO 15
   Array_1(i)=i
   .........
   .........
   .........
   .........
   .........
  Next i
EndSub

Sub DealWithArray_2
  FOR idx = 0 TO 13
   Array_2(i)=i
   .........
   .........
   .........
   .........
   .........
  Next i
EndSub

Sub DealWithArray_3
  FOR idx = 0 TO 10
   Array_3(i)=i
   .........
   .........
   .........
   .........
   .........
  Next i
EndSub

Sub DealWithArray_4
  FOR idx = 0 TO 15
   Array_4(i)=i
   .........
   .........
   .........
   .........
   .........
  Next i
EndSub

SXlee

Comments

  • ZootZoot Posts: 2,227
    edited 2011-02-28 18:24
    Why can't you use your first example and pass the value as Ubound as parameter? Unless you want to do a read or something to be able to loop through a list of arrays and do stuff to them, e.g.
    arrLen1 CON 14
    arrLen2 CON 10
    arrLen3 CON 9
    arrLen4 CON 4
    
    arr1 VAR Byte(arrLen1)
    arr2 VAR Byte(arrLen2)
    arr3 VAR Byte(arrLen3)
    arr4 VAR Byte(arrLen4)
    
    arrLens:
    DATA arrLen1
    DATA arrLen2
    DATA arrLen3
    DATA arrLen4
    
    '....
    
    FOR i = 0 TO 3 ' 4 arrays
       READ arrLens + i, uBound
       FOR j = 0 TO uBound
           LOOKUP i, [ @arr1, @arr2, @arr3, @arr4 ], W
           ASM
           ADD W, j
           MOV FSR, W
           ' now do something to ind, e.g.
           INC IND
           BANK __DEFAULT
           ENDASM
       NEXT
    NEXT
    
    
  • SXleeSXlee Posts: 47
    edited 2011-03-01 03:04
    Thank you Zoot, your solution is simple and elegant. :thumb:

    The Ubound parameter was not my first concern, pointing to an Array was my first.
    But if you can do it with Ubound you can do it with an array.

    Thank you!

    SXlee
Sign In or Register to comment.