[23 May 2006] Creating a Table

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
Oliver

[23 May 2006] Creating a Table

Post by Oliver »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 23 May 2006 19:20:37 +0100

Well, I know this is probably yet another basic question, but I have to admit that I have some problems to understand how working with tables.

What I want to do is open a textfile and store every line into a table field. Here is my (none working) code sniplet:

Code: Select all

test = {}
a = 0

OpenFile(1, "Games.txt", #MODE_READ)
While Not Eof(1) do test[a] = (ReadLine(1), a+1)
CloseFile(1)                 
Hollywood stops with an error, but I am not sure how to solve that, my guess is that I have to construct the counter another way. But how? Again, sorry for such basic things, but I went through that this the whole afternoon and it seems that I am somewhat blocked ;)

regards Oliver
User avatar
airsoftsoftwair
Posts: 5914
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[23 May 2006] Re: Creating a Table

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 23 May 2006 23:09:41 +0200
Well, I know this is probably yet another basic question, but I have to admit that I have some problems to understand how working with tables.

What I want to do is open a textfile and store every line into a table field. Here is my (none working) code sniplet:

Code: Select all

test = {}
a = 0

OpenFile(1, "Games.txt", #MODE_READ)
While Not Eof(1) do test[a] = (ReadLine(1), a+1)
CloseFile(1)                 
Hollywood stops with an error, but I am not sure how to solve that, my guess is that I have to construct the counter another way. But how? Again, sorry for such basic things, but I went through that this the whole afternoon and it seems that I am somewhat blocked ;)
Oh, that's easy. Use:

Code: Select all

While Not Eof(1)
 test[a] = ReadLine(1)
 a=a+1
Wend
You must not use the DO keyword because that is only meant for a short while loop which only accepts one statement in the loop. In your case, however, you need two statements, viz.

1. ReadLine()
2. Increase a by 1

See the documentation for more information on short loops and full loops.
Locked