Moving file pointer

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Moving file pointer

Post by bjb007 » Wed Feb 13, 2008 6:53 pm

I wrote my prog to read from a file...

put -36 to -1 of myData....

then

put -1 to -5 of myData....

That worked OK

When I reversed these two lines it wouldn't work.
Seems that the file pointer is at -5.

Is there a way to move it using EOF?

I expect that 'read to EOF' would work but
would prefer 'go to EOF' or similar.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Moving file pointer

Post by Mark » Wed Feb 13, 2008 10:41 pm

bjb007,
bjb007 wrote:I wrote my prog to read from a file...

put -36 to -1 of myData....

then

put -1 to -5 of myData....
I don't have the faintest idea what that means. It isn't valid Transcript. What are you trying to do? What is the actual script?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Moving file pointer

Post by bjb007 » Wed Feb 13, 2008 11:23 pm

That's pseudo-code just to give the general idea.

Usually when a file is read the "pointer" or position
stays at the end of the last read. So if you want to
read again in some other location in the file you either
have to close and open or, in most languages, you can
send the pointer to the start or end (EOF) of the file.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Feb 13, 2008 11:38 pm

bjb007,

You might want to read the entry for "read from file" in the built-in docs.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Re: Moving file pointer

Post by Mark Smith » Wed Feb 13, 2008 11:55 pm

The file operation you're looking for is "seek"

Code: Select all

seek to 35 in file someFile
Best,

Mark

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Feb 14, 2008 12:01 am

Hi Mark Smith,

Actually, it is possible to start reading from a file at a particular byte, without using the seek command.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Ah! Seek...

Post by bjb007 » Thu Feb 14, 2008 12:51 am

Thanks everyone for the help.

Seems that the ravages of time are taking their toll.
I didn't remember that one. Seek. Seek. Seek.

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Thu Feb 14, 2008 2:27 am

Mark wrote:Hi Mark Smith,

Actually, it is possible to start reading from a file at a particular byte, without using the seek command.

Best,

Mark
Quite so, I'd forgotten about 'read from ... for ... at..."

Best,

Mark

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

File Pointer

Post by bjb007 » Thu Feb 14, 2008 1:22 pm

Thanks all for comments but still seems to be no
way to go to start or end of file without closing
and re-opening except "Read to EOF" which seems
to put the whole file into variable "it".

BTW haven't seen anything in the docs about

1. Releasing variables

2. Meanings of error messages.

Any info would be appreciated.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Fri Feb 15, 2008 12:36 am

from the docs i gather that this should work, why doesn't it for you?

Code: Select all

read at 23 for 20
read at theByte until end
variables are released when the handler quits, unless when you specified them as global or local (local with caveat). If you forcibly want to get rid of data, most of the time it's enough to put empty int a var. To really delete variables, check out the "delete variable" command in the documentation.

The errors you get in rev are most of the time not helpful, often they point to the wrong line, have the wrong description, and/or are otherwise unhelpful. On the plus side you'll learn to make code that has almost no errors sooner or later. If you got a special case you want to have more information about, then post your code, and the error that rev reports.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply