Notifications
Clear all

[Closed] Reading Text file

Hi All
I’m trying to simply read each line of a .txt file I have. I can’t seem to get the results I want, the script is:


f = openfile “C:\GeoTime.txt”

while not eof f do

(

inputData = filterstring (readLine f) “,”

)

close f

print “Line = “+inputData[1]


my GeoTime.txt simply has 3 lines ( for now ) like this:

Holocene
0
0.01

when I run my script it prints 0.01 for inputData[1] where I expected Holocene…?

Please help, I’m sure I’m doing something stupid!!

Thanks

2 Replies

Hi dude

 I solved similar problem few days ago and maybe this can help you.

http://forums.cgsociety.org/showthread.php?f=98&t=833009

 Cheers
 JHN

f = openfile "C:\\GeoTime.txt"
inputData = #() -- define as array
  while not eof f do
  (
   append inputData (filterstring (readLine f) ",")
  )
  close f

for line in inputData format "%" line

  print "Line = "+inputData[1][1]
  print "Line = "+inputData[2][1]
  print "Line = "+inputData[3][1]
  

You where constantly overwriting inputData, so I define it as array and append to it, that way when the reading is done, you’re left with an array which you can use to iterate over.

Hope this helps,
-Johan