Fill an array from an (unreferenced) list?

690 views
Skip to first unread message

liwenna

unread,
Aug 4, 2009, 5:13:01 AM8/4/09
to E-Prime
Hi all!

I got something....

Does anyone know how to fill an array with words from an
(unreferenced) list???

Elaborated background info:
I'm working on a NAP task which demands control over two pairs of
stimuli in consecutive trials. I.E. a prime trial may show a negative
distractorword and a negative targetword and is followed by a probe
trial that shows a neutral distractorword and a positive targetword.
To put it differently: each trials consists of 2 displays with 4
stimuli in total and control over which type of word (pos neg neutral)
appears in which position is needed. Moreover... blocks of trial
(pairs) are repeated and the stimuliwords need to be randomized each
time.

I got this all working by using arrays. I got separate arrays for
negative, positive and neutral words and at the beginning of each
block these 3 arrays are randomised and then used to fill a triallist.
The trialpair described above for instance is one level in this list
that has four attributes (primetarget = negarray(0) primedistractor =
negarray(1), probetarget = posarray(0) and probedistractor = neutarray
(0), etc etc, with one level per trialpair.

So far so good.... but now about filling the arrays... in my testsetup
I filled the arrays by typing out each word in the array-inline for
instance:

negarray(0) = "negword1"
negarray(1) = "negword2"
etc

This works fine but it means that each single word in every list has
to be written out in the inline and completed with " " at the start
and beginning. As I like my setups to be 'versatile' and easy to
adjust for later use I would think it to be more elegant (and less of
a pain in adding " -wise) if the stimuliwords could more simply be
pasted in to an (unreferenced) list and the arrays being filled from
these lists.... but I can't get this to work.... I tried it with
colon notation and unreferenced lists ( negarray(0) = [negative:0] and
with getattrib/setattrib setattrib ( "negarray(0)", [negative:0] as
well as negarray(0) = getattrib ([negative:0]) ), both in all kinds of
bracket-arrangements and with the list that contains the attribute
'negative' placed in different locations (trashthing, sessionproc,
blockproc, trialproc etc) but to no avail....

I'm just hoping that I'm majorly overlooking something and/or that
someone just happens to know how to do this. The task is working fine
as it is, I just think it would be more elegant if the arrays could be
filled from lists. Or could this perhaps be another instance of colon-
notation not working properly?

Best regards,

liwenna

Peter Quain

unread,
Aug 4, 2009, 6:03:28 AM8/4/09
to e-p...@googlegroups.com

If you want flexibility and to avoid finicky typing, perhaps you could:
- type the words in text documents, 1 word to a line. you have
seperate arrays for each stimulus type ... and you need to type the
stim sometime
- open the text documents to read, 1 at a time
- run a loop, reading each line of the document and saving it as the
string in each cell of your array

Something like this would allow lists of differing length to be read in.
...
' for 0 option base
Dim YourArray() As String
Dim s$ As String
Dim LineCount As Integer
Dim n As Integer

' Find out the number of lines
Open "YOURFILE.txt" For Input As #1
LineCount = -1
Do While Not EOF(1)
LineCount = LineCount + 1
Input #1, s$
Loop
Close #1

' make the array the size of the document...
ReDim YourArray(LineCount)

' Read in the stimuli
Open "YOURFILE.txt" For Input As #1
For n = 0 To LineCount
Input #1, YourArray(n)
Next n
Close #1

liwenna

unread,
Aug 4, 2009, 6:44:25 AM8/4/09
to E-Prime
Thank you for your quick reply Peter!

I will definitely try your suggestion! I never used external files to
feed info into e-prime so that's a nice thing to 'get my hands on'.

However: doesn't the use of external files influence timing?
(anyone?). And if so: would this also be the case if the whole
retrieveing of info is done in the beginning of a blockproc BEFORE the
trials start running (i.e. in my set-up combined with your/Peter's
suggestion, arrays would be filled, randomised and used to fill a
triallist BEFORE each block of trials starts running).

I think I won't have time to try it before tomorrow but I'll post back
when succesfull (and also when not actually ;) )

Thanks again!

liwenna

liwenna

unread,
Aug 5, 2009, 5:08:09 AM8/5/09
to E-Prime
The script works just fine Peter!

(only the s$ was not allowed but simply replacing it by a normal word
does the trick)

Thanks so much!


Now the timing question remains.... anyone experience with that?

Peter Quain

unread,
Aug 5, 2009, 5:13:16 AM8/5/09
to e-p...@googlegroups.com

good, i hadn't run that code. there should be no timing problems
because of the import routine - that is all going on before your
trial procedure starts, i gather, so been and gone by the time
important things are afoot.

Can you post how you go about populating list from array, if you have
the time? ta
Message has been deleted

liwenna

unread,
Aug 5, 2009, 8:26:49 AM8/5/09
to E-Prime
I had a REAL long post but then realised that your question can
actually be answered much simpler.

Below is part of the filling code. It filles level 3 and 4 of the
triallist (so trialpair 3 and 4 that are trials 5/6 and 7/8 as there
are two trials (prime and probe) to each trialpair. Triallist
therefore consists of 4 attirubtes primedistractor, primetarget,
probedistractor and probetarget, to gain control over 2 consecutive
'trials' (two slides prime and probe on the trialproc). Poswords,
neutwords and negwords are the names of the three arrays." Triallist
setattrib 3 " refers to the 3rd level of triallist.

'Fill level 3 of Triallist (negative control)
TrialList.SetAttrib 3, "primedistractor", poswords(3)
Triallist.setattrib 3, "primetarget", poswords(4)

Triallist.setattrib 3, "probedistractor", neutwords(2)
Triallist.setattrib 3, "probetarget", negwords(3)


'Fill level 4 of Triallist (negative experimental)
TrialList.SetAttrib 4, "primedistractor", negwords(4)
Triallist.setattrib 4, "primetarget", poswords(5)

Triallist.setattrib 4, "probedistractor", neutwords(3)
Triallist.setattrib 4, "probetarget", negwords(5)

It's really very simple, although it's a bit of a hassle to type it
all out (should be able to automate it... ) but yet it's far more
simple than the version I received from someone else who had done all
the randomizing by hand.

Thanks again for your help Peter!

Best regards,

liwenna

Caleb J. Picker

unread,
Feb 2, 2011, 2:21:08 PM2/2/11
to e-p...@googlegroups.com
Hello,

I have a question. I looked in the e-basic help and it says that the Input[#] function does this:

Reads data from the file referenced by filenumber into the given variables.

Why is it the case that when you type '...For Input as #1' that his necessarily reads one line at a time. What I am saying is, I do not understand this function. What does the Input [#] function really mean? If I were to change the '1' value to '2', would this input every other line? Would inputting a large integer value read every nth value of that integer?

Thanks in advance.

Caleb

liwenna

unread,
Feb 3, 2011, 5:54:25 AM2/3/11
to E-Prime
If I remember correctly the number is simply a denominator for 'the
input' ...

so... in the above example I needed 3 different .txt files to be put
into 3 different arrays... (one with positive words, one negative and
one neutral). I'll check for you tomorrow but if I remember correctly
I repeated the script three times but used input#1, input#2 and
input#3. That would make the number just 'a name' given to that input
function.

"the file referenced by filenumber" would then refer to this line in
the above code: Open "YOURFILE.txt" For Input As #1

liwenna

unread,
Feb 4, 2011, 7:41:39 AM2/4/11
to E-Prime
So I checked it and it is indeed like I described above... just a
denominator, as far as I can see. In addition, I checked what would
happen if I would use input #1 for the separate inputs and things work
just fine... obviously in this script (partly pasted below) the first
file is opened(as #1), the array is filled, and then #1 is closed
before the next file is opened as input#1. If for some reason you'd
first want to open several files simultaneously and only later fill
arrays or whatever you're going to do with the info from the files...
it would of course be needed to give a separate 'name' #1, #2, etc) to
each of the inputs from different files.

best,

liw


'fill the array negwords
'Read in the stimuli into the array negwords
Open "negativewords.txt" For Input As #1
For n = 0 To 17
Input #1, negwords(n)
Next n
Close #1

'fill the array poswords
'Read in the stimuli into the array poswords
Open "positivewords.txt" For Input As #1
For n = 0 To 17
Input #1, poswords(n)
Next n
Close #1

David McFarlane

unread,
Feb 4, 2011, 2:56:11 PM2/4/11
to e-p...@googlegroups.com
Caleb,

This is an elementary Visual Basic question. You should be able to
find more detailed answers by doing a web search (e.g., "vba input
function")., or look in the "VBA for Dummies" book.

Best,
-- David McFarlane, Professional Faultfinder

Reply all
Reply to author
Forward
0 new messages