Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:39 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Using SEEK

Author Message
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 121
Posted: 01:43am 26 Mar 2023
Copy link to clipboard 
Print this post

Hi all

I am trying to print some lines from a file using the seek command.
I can get it to print from the start of the file using forward.bas but I really want it to print from the bottom up.
I have tried manipulating with the value "y" but keep getting an error.
Any ideas?


ps
I found that this program runs forward in the old version of MMBasic but not in the latest.

Chrisk


forward.zip

Originally placed this in Windmills by accident  
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1245
Posted: 01:55am 26 Mar 2023
Copy link to clipboard 
Print this post

Hi,
Which firmware version and which hardware are you using? It should work with the latest versions for the Picomite (=>A25).

Regards
Michael

EDIT:

i=0 ????

[8] Seek #1, i  'Points to start of data location
Error : 0 is invalid (valid is 1 to 2147483647)


Try i=1  
Edited 2023-03-26 12:01 by twofingers
causality ≠ correlation ≠ coincidence
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 121
Posted: 04:34am 26 Mar 2023
Copy link to clipboard 
Print this post

Hi Twofingers

I have tried out your suggestion with my Windows MMBasic Ver 5.05.05 and it works. Thanks for that.

The old DOS MMBasic Ver 4.5 worked with i = 0.
With i = 1 the program did not print the first character in line 1.


I use the Micromite plus 64.

The program (forward) works on the MM+64 with i = 0 which I will change to i = 1
but I would like to have it read in reverse line order.

I use DOS MMBasic to verify parts of my program of which this is only a part.

Thank you

Chrisk
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1245
Posted: 11:45am 26 Mar 2023
Copy link to clipboard 
Print this post

  Chrisk said  I use DOS MMBasic to verify parts of my program of which this is only a part.

You can customize your program by using "mm.device$" to query the hardware used.

If you're reading your data forward and from the beginning of the file, you don't need to use Seek. You only need Seek to read backwards.
causality ≠ correlation ≠ coincidence
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 121
Posted: 06:47am 27 Mar 2023
Copy link to clipboard 
Print this post

Hi again

I am not sure I expressed myself clearly enough.

I am reading the file gtest2 and sending each line to a LCD display.

Currently "forward.bas" displays the line 02-03-20   08:12 first.

I am not sure how a program can read the line  16-09-20  07:45 which is actually the last line but display it first.



'forward.bas
' Displays stored data in gtest2.txx to a line in an LCD display
i = 1
OPEN Prevd$ FOR RANDOM AS #1
y = LOF(#1) 'Determines number of bytes in file
print y
seek #1, i  'Points to start of data location
DO
LINE INPUT #1, dat$
print
print dat$
pause 500
print
LOOP UNTIL EOF(#1)
CLOSE #1
end



02-03-20   08:12
04-04-20   09:23
06-05-20   10:45
08-06-20   12:27
12-07-20   08:12
14-08-20   09:23
16-09-20   07:45



Chrisk
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 121
Posted: 06:51am 27 Mar 2023
Copy link to clipboard 
Print this post

Obviously from the look of the post I don't know what I am doing in regard to posting correctly. Should have previewed first.
Sorry about that.

Chrisk
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6102
Posted: 07:07am 27 Mar 2023
Copy link to clipboard 
Print this post

Are the liens equal length?
how many lines are expected - can they be loaded into an array if memory is sufficient?

Jim
VK7JH
MMedit   MMBasic Help
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 532
Posted: 08:07am 27 Mar 2023
Copy link to clipboard 
Print this post

If the lines really have the same length (15 bytes?), you can calculate number of lines from file size:
lineLen = 15 'for example, need to be properly set
fileSize = MM.INFO(FILESIZE file$) 'get file size
numLines = fileSize / lineLen 'not needed, just for information (progress bar?)
actLine = fileSize - lineLen 'pointer to last line

then you can seek
SEEK #1, actLine 'set file pointer to actual line
INC actLine, -lineLen 'decrease pointer, go one line back

Edited 2023-03-27 18:09 by jirsoft
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6102
Posted: 10:12pm 27 Mar 2023
Copy link to clipboard 
Print this post

'reverse listing
Prevd$ = "C:\Users\Jim\Documents\myapps\maximite\apps - Copy\listing.txt"
linelength = 18 ' includes <CRLF>
OPEN Prevd$ FOR RANDOM AS #1
y = LOF(#1) 'Determines number of bytes in file
PRINT "Y = ";y
y = y - linelength + 1
FOR i = y TO 1 STEP -linelength
SEEK #1, i  'Points to start of data location

dat$ = INPUT$( linelength-2,#1)
PRINT dat$

NEXT i
CLOSE #1



You often have to experiment with line length due to different line endings.
Make sure that your data doesn't have the occasional TAB. That can upset the line length.

Jim
VK7JH
MMedit   MMBasic Help
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 121
Posted: 12:18am 28 Mar 2023
Copy link to clipboard 
Print this post

Thank you guys
It's working as I require whilst testing it with MMBasic. No need to implement in micro at my daughters place.
I did have to change the line  y = y - linelength + 1 to y = y - linelength - 1
as it was cutting off the first 2 characters of each line. Not sure why.

Jim
What is the significance of the ; in the line PRINT "Y = ";y
It doesn't appear to change anything whether it is there or not.


To you all  
Chrisk
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 121
Posted: 12:50am 28 Mar 2023
Copy link to clipboard 
Print this post

Back again
Apologies to Jim  

On another set of data for the data file I found I had to change the line back to what you had written i.e. y = y - linelength + 1

Chrisk
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6102
Posted: 01:38am 28 Mar 2023
Copy link to clipboard 
Print this post

  Quote  What is the significance of the ; in the line PRINT "Y = ";y
It doesn't appear to change anything whether it is there or not.


From the help files:
  Quote  Outputs text to the console (either the VGA screen or the serial or both is they are available). Multiple expressions can be used and must be separated by either a:

·   Comma (,) which will output the tab character

·   Semicolon (;) which will not output anything (it is just used to separate expressions).

·   Nothing or a space which will act the same as a semicolon.

I prefer to use the ; rather than nothing. It makes the line of code clearer (to me).

  Quote  On another set of data for the data file I found I had to change the line back to what you had written i.e. y = y - linelength + 1


It all depends if your data ends with <CRLF>, no end of line or two <CRLF> pairs.
Text files often end up with an extra blank line at the end.

Your file that needed  y = y - linelength - 1 didn't have any end-of-line.

The safe way is to fetch more than required and search the string looking for the end-of-line. Then use that as the starting point.

Jim
VK7JH
MMedit   MMBasic Help
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 121
Posted: 03:39am 28 Mar 2023
Copy link to clipboard 
Print this post

Thanks Jim much appreciated

ChrisK
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024