loading external files into Lists - examples or potential solutions?

Paul Jackson paulj at psy.uq.edu.au
Tue Mar 3 20:53:08 UTC 2009


Here is a function that I use to load text files into a List. In this
case the list is called lstTrials and it will only have 2 columns
"TrialStimulus" and "TrialCorrectResponse". I have used variations on
this function for over 5 years with no problems. Note that it can make
the result file look a little messy because it creates a new list
everythime it is run. I found that trying to use the same list can cause
problems. This has only been testing in v1.


Sub LoadBlockData(TempFilename as String)
	On Error GoTo E
	Dim LevelCount As Long
	Dim Count as Long
	Dim TrialStimulus As String
	Dim	TrialCorrectResponse As Long
	
	If FileExists(TempFilename) = False Then
		Err.Raise 1001,,"Cannot find file '" & TempFilename &
"'"
	End If
	
	LevelCount=0
	Set listTrials = New List
	'listTrials.Name="listTrial"
	listTrials.AddAttrib "TrialStimulus"
	listTrials.AddAttrib "TrialCorrectResponse"

	Open TempFilename For Input As #1
	Do While Not EOF(1) 
		TrialStimulus="-1"
		TrialCorrectResponse=-1
		Input #1, TrialCorrectResponse, TrialStimulus
		If TrialCorrectResponse=-1 Then
			Err.Raise 1001,,"Incorrect Format, or Blank Line
(expected TrialCorrectResponse value '0' or '1')"
		End If
		If TrialStimulus="-1" Then
			Err.Raise 1001,,"Incorrect Format, or Blank Line
(expected TrialStimulus value)"
		End If
			
		LevelCount=LevelCount+1
		If LevelCount>listTrials.Size Then
			listTrials.AddLevel LevelCount
		End If
		listTrials.SetProc LevelCount, "procTrial"
		listTrials.SetAttrib LevelCount, "TrialCorrectResponse",
TrialCorrectResponse
		listTrials.SetAttrib LevelCount, "TrialStimulus",
TrialStimulus
		'LoadMessage
	Loop
	Close
	
	Set listTrials.TerminateCondition=Samples(listTrials.Size())
	Set listTrials.ResetCondition=Samples(listTrials.Size())
	Set listTrials.Order = SequentialOrder

	Exit Sub
E:
	Close
	Err.Raise 1001,,"Loading Block File Data Failed." & ebcr &
Err.Description & ebcr
End Sub

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
 Paul R. Jackson
 
 Experimental Programmer
 School of Psychology
 University of Queensland
 
 E: paulj at psy.uq.edu.au
 P: 33656950
 W: www.psy.uq.edu.au/~paulj
~~~~~~~~~~~~~~~~~~~~~~~~~~~~


> -----Original Message-----
> From: e-prime at googlegroups.com [mailto:e-prime at googlegroups.com] On
> Behalf Of TN
> Sent: Wednesday, 4 March 2009 2:41 AM
> To: E-Prime
> Subject: loading external files into Lists - examples or potential
> solutions?
> 
> 
> Hi,
> 
> I was wondering if anybody had an example or could please point me to
> an example of an E-Prime (v2 preferably) program which loads external
> files into List.
> 
> For my program, we are trying to load different variable values for
> various variable.   I have found where you tell Eprime to load the
> file (in List, go to "Property Page," General Tab) but I cannot seem
> to create a file that will load.  I tried a .xml and a .csv - both
> created by excel.  I don't think EprimV2 likes .csv and the .xml file
> had errors.  I put in the necessary Column headers (weight, nested,
> procedure) but it errored on the "Procedure" column.  It claimed my
> Procedure name was not valid, even though I could see that particular
> Trial Procedure directly under the List in the program.  I'm not
> limited to using .xml or .csv files - that's just where my previous
> research lead me.
> 
> I am stuck, have looked through some online examples, EPrime's support
> forum and have glanced through the manuals but haven't found any
> solutions.  I would be grateful for any help or examples.
> 
> Thanks,
> ~Tiffany
> 
> 

--~--~---------~--~----~------------~-------~--~----~
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