Announcement

Collapse
No announcement yet.

Passing MultiDimension Arrays into SUBs

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

  • Arthur Gomide
    replied
    Originally posted by Daniel Raymer:
    and the SIZE parameter ...
    Daniel,

    There is no SIZE parameter! See the example below:
    Code:
    DIM Matrix(1 TO 5, 2 TO 10, 3 TO 15)
    CALL ArrayTest(Matrix(), 1, 2)
    
    
    SUB ArrayTest(alfa(3), Number1, Number2) ' alfa(num-of-dimensions)
     PRINT UBOUND(alfa(1)) '<- print 5
     PRINT LBOUND(alfa(1)) '<- print 1
     PRINT
     PRINT UBOUND(alfa(2)) '<- print 10
     PRINT LBOUND(alfa(2)) '<- print 2
     PRINT
     PRINT UBOUND(alfa(3)) '<- print 15
     PRINT LBOUND(alfa(3)) '<- print 3
     ...
    END SUB
    ------------------
    Arthur Gomide
    Como diria nosso profeta da bola, Dadá Maravilha:
    "Para toda Problemática existe uma Solucionática!"



    [This message has been edited by Arthur Gomide (edited October 03, 2006).]

    Leave a comment:


  • Michael Mattias
    replied
    I don't see any SIZE in the help file, nor do I remember one.

    Simplified: When you pass an entire array as a parameter, it's available to your procedure and you can do anything you want with it. And anything you do to it in that procedure will be reflected back to the calling procedure. It's just like passing any other variable by reference.


    Leave a comment:


  • Daniel Raymer
    replied
    Thanks!

    So, my code is fine and the SIZE parameter that is described in the manual is just for use in the SUB, and has nothing to do with dimensioning the local array in the SUB.
    Right?

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

    Leave a comment:


  • Michael Mattias
    replied
    >In the following, C#() is 4x4.

    Meaning, two dimensions; which is exactly what you told it here..
    Code:
    SUB HOMCORD(byval S!,byval DX!,byval DY!,byval DZ!,byval Roll!,byval Pitch!,byval Yaw!,_ 
            byval Dist!,[b]C#(2)[/b])
    The current number of elements for any dimension is detected automatically.


    Leave a comment:


  • Daniel Raymer
    started a topic Passing MultiDimension Arrays into SUBs

    Passing MultiDimension Arrays into SUBs

    I just noticed that code I wrote years ago to pass 4x4 arrays into and out of SUBs doesn't seem to specify the dimensions of the array in the sub. The manual says to include SIZE after the array name, but doesn't say what to do when there are more than one dimension, nor what to do if you have other variables to pass as well. In the following, C#() is 4x4. How do I specify that in the SUB? I suspect that PB gives me 10x10 by default, chewing up memory and slowing down my code.

    CALL HOMCORD(0.,CompX!,CompY!,CompZ!,CompRoll!*Deg2Rad#,CompPtch!*Deg2Rad#,CompYaw!*Deg2Rad#,0.,CompC#())

    SUB HOMCORD(byval S!,byval DX!,byval DY!,byval DZ!,byval Roll!,byval Pitch!,byval Yaw!,byval Dist!,C#(2))
    DIM DYNAMIC A#(4,4),B#(4,4) 'local to this SUB only


    (To satisfy the curiosity of lurkers like me, this is part of a CAD code and sets up Homogeneous Coordinate Transformations for viewing.)


    ------------------
Working...
X