BeSly Software Solutions About yab Demos About us Admin


seek() -- change the position within an open file

open 1,"foo" 
seek #1,q 
seek #1,x,"begin" 
seek #1,y,"end" 
seek #1,z,"here" 

The seek-command changes the position, where the next input (or peek) statement will read from an open file. Usually files are read from the beginning to the end sequentially; however sometimes you may want to depart from this simple scheme. This can be done with the seek-command, allowing you to change the position, where the next piece of data will be read from the file.

seek accepts two or three arguments: The first one is the number of an already open file. The second one is the position where the next read from the file will start. The third argument is optional and specifies the the point from where the position (the second argument) will count. It can be one of:

begin -- Count from the beginning of the file.

end  -- Count from the end of the file.

here -- Count from the current position within the file.

open #1,"count.dat","w" 
for a=1 to 10 
	print #1,"00000000" 
	if (a<10) print #1,"" 
next a 

dim count(10) 
	if (mod(i,1000)=0) print "." 
	seek #1,9*x,"begin" 
	print #1,curr$; 

This example increments randomly one of ten counters (in the array count()); however, the result is always kept and updated within the file count.dat, so even in case of an unexpected interrupt, the result will not be lost.

Related: tell, open, print, peek