Return array from function

liwenna liwenna at gmail.com
Mon Dec 12 15:24:06 UTC 2011


Thanks for that info, David!

I'll absolutely take up your advice of defining boundaries in the
future since the 0-level regularly confuses me when it try to use
loops to fill/pull arrays ^.^

On Dec 12, 3:44 pm, David McFarlane <mcfar... at msu.edu> wrote:
> Eline,
>
> Glad that liw solved it for you.  I just want to add a few more details
> in case anyone else stumbles on this thread.
>
> By *default*, array indexes in E-Prime/E-Basic start at 0.  But you may
> change that to start instead at 1 using the "Option Base 1" statement in
> the global User script area -- see the Option Base topic in the E-Basic
> Help facility.
>
> You may also override the default on any array by explicitly declaring
> its bounds in the Dim statement -- see the Dim topic in the E-Basic
> Help.  E.g., if you were to say
>
>         Dim U(1 to 3, 1 to 3) As Variant
>
> in your original code, then the array initialization loop should work
> just fine.
>
> Exactly because this array index issue can get so confusing, I have
> taken to always explicitly declaring the index bounds when I declare
> arrays, that way there is no question.  I would advise you and everyone
> else to do the same.
>
> -- David McFarlane
>
>
>
>
>
>
>
> liwenna wrote:
> > Must admit that I do not understand the code but I do happen to know
> > that array's start counting levels at 0, so the "top left" cell in a
> > 3*3 array is U(0,0) and the bottom right U(2,2). => if you let i and j
> > run from 0 to 2 rather than 1 to 3, that may help?
>
> > best,
>
> > liw
>
> > On Dec 12, 11:48 am, ELine <elin... at hotmail.com> wrote:
> >> Hello again
>
> >> I have problems returning a 3x3 array from a function. I have an
> >> experiment with 9 conditions and to keep things simple I organized
> >> them in a 3x3 array. I want to keep track on the number of trials pr
> >> condition by updating this array in the end of each trial using a user-
> >> specified function that returns a 3x3 array containing one 1 (rest is
> >> 0s) specifying which trial has been run.
>
> >> my problem is not with the function itself, but with returning a 3x3
> >> array. I've tried something like this (but of course more
> >> complicated):
>
> >> Function UpdateArray(A As Integer, B As Integer) As Variant
> >>     Dim U(3,3) As Variant
>
> >>      for i= 1 to 3
> >>         for j= 1 to 3
> >>         U(i,j)=0
> >>         next j
> >>      next i
> >>      U(A,B)=1
>
> >>     UpdateArray=U
>
> >> End Function
>
> >> When compiling E-Prime returns the error: Cannot assign whole array. I
> >> also tried with integer instead of variant, but it still doesn't work.
> >> And I've tried including ReDim, but without any luck.
>
> >> Can anyone help me?
>
> >> ELine

-- 
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.



More information about the Eprime mailing list