how to define an array

814 views
Skip to first unread message

sihua xu

unread,
Nov 3, 2013, 9:47:46 PM11/3/13
to e-p...@googlegroups.com
Dear all
    I am having problems with the definition of the array and assign the value in the e-prime, for example, I want to define two arrays. the first one  including 36 units and values and the second one including 12 units and values.  we should  get one value randomly from each array, and then stop the program by comparing the size of them.
my main question is how to define the array including 36 or 12 units, how to get the value from the array randomly and compare them?
the two arrays as follows:
a[36] ={2,3,4,5,6,7,8,9,10,11,12,4,5,6,7,8,9,10,5,6,7,8,9,5,6,7,8,9,6,7,8,4,5,6,7,8}
b[12] = {12,7,8,2,6,3,9,10,4,5,11,9,10,11,12}

I would be grateful if anybody could help me with that
thanks




Sihua Xu

PhD
Department of psychology
Sun Yat-Sen University
Guangzhou, 510275
P. R. China

gorgeous yayuan geng

unread,
Nov 3, 2013, 10:23:08 PM11/3/13
to e-p...@googlegroups.com
Dear, 

you should defiine the array one by one like this, a(1)=2  a(2)=3
and you can random the array use the arrayrandomize method. then you can get a random number use random method ,then
randomizearray a 
t=random(1,ubound(a))
a(t) is what you want.
Hope this help. 


2013/11/4 sihua xu <xusi...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To unsubscribe from this group and stop receiving emails from it, send an email to e-prime+u...@googlegroups.com.
To post to this group, send email to e-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/e-prime/CAPEBGuZ1_p6CvL43-B6720CnppEsVi0P2j4Gn5W5AXNN9kjKow%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

David McFarlane

unread,
Nov 5, 2013, 11:11:07 AM11/5/13
to e-p...@googlegroups.com
Sihua,

Judging from your example, I take it that you have a background in
C/C++, which has an elegant way of initializing arrays in
code. Standard VBA might include a similar (though more clumsy)
mechanism, but that has been left out of E-Basic. So as the previous
respondant says, you just need to assign each array element in turn
with its own assignment statement. Of course you also need to first
declare your arrays, thus,

Dim a(1 to 36) as Integer ' use explicit array bounds to
reduce confusion
Dim b(1 to 12) as Integer
a(1) = 2
a(2) = 3
...
b(1) = 12
b(2) = 7
...

and if you like you can collapse that using the colon statement separator,

Dim a(1 to 36) as Integer ' use explicit array bounds to
reduce confusion
Dim b(1 to 12) as Integer
a(1) = 2: a(2) = 3: ...
b(1) = 12: b(2) = 7: ...

but it is still clumsy and ugly no matter how you do it. This is
really elementary VBA programming, so for more info I recommend an
intro VBA programming book such as "VBA for Dummies".

If it were me, I might instead use a List for initializing and
randomizing, but that is more than I can go into here.

-----
David McFarlane
E-Prime training
online: http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter: @EPrimeMaster (https://twitter.com/EPrimeMaster )

/----
Stock reminder: 1) I do not work for PST. 2) PST's trained staff
take any and all questions at https://support.pstnet.com , and they
strive to respond to all requests in 24-48 hours, so make full use of
it. 3) In addition, PST offers several instructional videos on their
YouTube channel (http://www.youtube.com/user/PSTNET ). 4) If you do
get an answer from PST staff, please extend the courtesy of posting
their reply back here for the sake of others.
\----


At 11/3/2013 10:23 PM Sunday, gorgeous yayuan geng wrote:
>Dear,
>
>you should defiine the array one by one like this, a(1)=2 a(2)=3
>and you can random the array use the arrayrandomize method. then you
>can get a random number use random method ,then
>randomizearray a
>t=random(1,ubound(a))
>a(t) is what you want.
>Hope this help.
>
>
>2013/11/4 sihua xu <<mailto:xusi...@gmail.com>xusi...@gmail.com>
Reply all
Reply to author
Forward
0 new messages