atarionline.pl viewing file in TB - Forum Atarum

    Jeśli chcesz wziąć udział w dyskusjach na forum - zaloguj się. Jeżeli nie masz loginu - poproś o członkostwo.

    • :
    • :

    Vanilla 1.1.4 jest produktem Lussumo. Więcej informacji: Dokumentacja, Forum.

      • 1: CommentAuthorw1k
      • CommentTime19 Apr 2010 22:04
       
      i have program
      10 DIM A$(120)
      20 OPEN #3,4,0,"D:file.txt"
      30 INPUT #3;A$
      40 ? A$
      50 CLOSE #3


      this load only 120 letters? how to do to read a whole text?
      • 2: CommentAuthormono
      • CommentTime19 Apr 2010 22:04
       
      10 DIM A$(1000)
      20 OPEN #3,4,0,"D:file.txt"
      30 TRAP 70
      40 INPUT #3;A$
      50 ? A$
      60 GOTO 40
      70 CLOSE #3
      80 TRAP 32768

      INPUT reads text file line by line, so try to declare A$ with accurate size.
      • 3:
         
        CommentAuthorpirx
      • CommentTime19 Apr 2010 22:04
       
      loop it
      • 4:
         
        CommentAuthorlarek
      • CommentTime19 Apr 2010 22:04
       
      10 OPEN #1,4,0,"D:filename.ext"
      20 TRAP#ERR:CLS
      30 DO
      40 GET #1,BYTE:? CHR$(27);CHR$(BYTE);
      50 LOOP
      60 #ERR
      70 CLOSE #1
      • 5: CommentAuthorw1k
      • CommentTime19 Apr 2010 23:04
       
      mono: your example looks good, but that is to same
      pirx: how?
      larek: that program view text vertically.. like this

      s
      a
      m
      p
      l
      e

      t
      e
      x
      t

      :(
      • 6:
         
        CommentAuthorlarek
      • CommentTime19 Apr 2010 23:04 zmieniony
       
      40 .... ;


      line 40 on the end must be a sign ";"

      how the file will be a "RETURN" (155), it will be the same effect.

      ps. translated by google ;-)


      10 OPEN #1,4,0,"D:filename.ext"
      20 TRAP#ERR:CLS
      30 DO
      40 GET #1,BYTE:? CHR$(27);
      45 IF BYTE=155:?" ";:ELSE:?CHR$(BYTE);:ENDIF
      50 LOOP
      60 #ERR
      70 CLOSE #1
      • 7: CommentAuthormono
      • CommentTime19 Apr 2010 23:04
       
      @larek: Złapałem wreszcie :D Gościowi chodzi o wczytanie całego pliku naraz (dlatego dał tylko jedno INPUT). Nie da się tego zrobić jakimś BGETem?
      • 8:
         
        CommentAuthorlarek
      • CommentTime19 Apr 2010 23:04 zmieniony
       
      da się, ale trzeba wtedy liczyć się z tym, że nie wczytamy pliku większego niż dostępna pamięć.

      Można tak:
      10 DIM A$(32767): A=ADR(A$)
      20 A$=" ":A$(32767)=A$:A$(2)=A$
      30 OPEN #1,4,0,"D:FILENAME.EXT"
      40 TRAP #ERR
      50 BGET #1,A,32767
      60 #ERR : TRAP 40000
      70 CLOSE #1
      80 ? A$


      Niestety w tym przypadku instrukcja PRINT A$ daje niezbyt ładne efekty na ekranie (i w głośnikach) jeśli w podglądanym pliku mamy znaki sterujące. Poprzedni program odczytujący każdy bajt osobno i tak też go wyświetlający jest pozbawiony tej wady. No i można podglądać na ekranie plik dowolnej długości.
      • 9: CommentAuthormono
      • CommentTime19 Apr 2010 23:04 zmieniony
       
      Można było jakimś POKE zablokować interpretowanie znaków sterujących, po czym odblokować.

      Edit: POKE 766,1 blokuje interpretację, 0 odblokowuje. Tylko EOL (155) jest wykonywany.
      • 10: CommentAuthorw1k
      • CommentTime20 Apr 2010 09:04
       
      thanks everyone..
      Now i must change it so that the text moved after pressing the key if screen is full them.
      • 11: CommentAuthorw1k
      • CommentTime20 Apr 2010 09:04
       
      ok,
      how do to load txt files first and then looking where appropriate? for example through the menu

      A...FIRST TEXT
      B...SECOND TEXT..
      etc
      • 12: CommentAuthorw1k
      • CommentTime20 Apr 2010 15:04
       
      :(
      • 13:
         
        CommentAuthorzilq
      • CommentTime20 Apr 2010 16:04
       
      I don't know is this your solution.

      10 DIM A$(40)
      20 TRAP #END_READ
      25 GR.0
      30 OPEN #1,4,0,"D:MENU.TXT"
      35 FOR I=0 TO 25: REM FOR ALL LETTER
      40 INPUT #1,A$:? CHR$(65+I);": ";A$
      45 NEXT I
      50 # END_READ
      99 END


      and subprogram to make file "D:MENU.TXT"
      10 DIM A$(40)
      15 OPEN #1,8,0,"D:MENU.TXT"
      20 FOR I=0 TO 25
      25 ? CHR$(65+I);": ";:INPUT #16,A$
      30 IF A$(="" THEN 145
      35 ? #1;A$
      40 NEXT I
      45 CLOSE #1


      Example is in Turbo Bacis, but i don't see a problem to write in other language.
      I have hope, is this works :) (sorry for my english :D)
      • 14: CommentAuthorw1k
      • CommentTime20 Apr 2010 17:04 zmieniony
       
      hmm..
      I was thinking of something else :)
      i have menu
      A.....WHATS NEW
      B.....OTHER TEXT
      C.....OTHER TEXT 2



      each option load text from different file..
      how to do this?
      • 15:
         
        CommentAuthorzilq
      • CommentTime20 Apr 2010 20:04 zmieniony
       
      heh... now i understand :)
      its lots of various ways to doo this, but this is theme for a article, not a post

      base on your source:
      30 DIM BUF$(10240)
      ...
      170 IF B$="A" THEN FN$="D:UVOD.TXT":EXEC LOAD_FILE


      and now... :)

      10000 REM LOADING FILE (one chunk - lots of memory use!)
      10005 PROC LOAD_FILE
      (**)10007 BUF$(1)=CHR$(0):BUF$(10240)=CHR$(0):BUF$(2)=BUF$(1)
      10010 OPEN #1,4,0,FN$
      10015 TRAP #END_LOAD
      10020 BGET #1,ADR(BUF$),10240
      10025 # END_LOAD:CLOSE #1
      10030 ENDPROC


      * here, filling Buf$, becouse is needed to simple show, ex. using Print instruction. Notice: This solution, shows all bytes in BUF$ (all 10240 bytes)!!

      result: Loaded file in one chunk, but we don't know, how long is this chunk :/

      We can use INSTR instruction from Turbo Basic to find first heart ( chr$(0) ) in buffer and truncate BUF$ to this value. Example:
      10005 PROC LOAD_FILE
      ...
      10030 LN=INSTR(BUF$,CHR$(0))
      (*)10035 BUF$=BUF$(1,LN-1)
      10040 ENDPROC


      * i can't remember, it is good construction :) 100% works :D

      Now, we have full usable procedure to load text from file, and we can simple show content of variable BUF$ using:
      PRINT BUF$
      Print BUF$(1,100) to show fragment


      I hope you understand my explains :)

      TurboBasic Rulez ]:->
      • 16: CommentAuthorw1k
      • CommentTime20 Apr 2010 22:04
       
      when i try it then ERROR 9 DIM AT LINE 170

      when i type
      35 DIM FN$(19)
      then
      ERROR- 129 IS OPEN AT LINE 10010..

      this is so frustrated
      I thought it would be easier. looked so :(
      • 17: CommentAuthorw1k
      • CommentTime20 Apr 2010 22:04
       
      ok, i done it.. it is little different, but still works..
      how i fix error 136?
      • 18:
         
        CommentAuthorzilq
      • CommentTime20 Apr 2010 22:04
       
      sorry, thats my fault. I dont spot your "declaration" (open channel #1) and i miss DIM FN$(19) :/ once again sorry.

      HINT: If you programming in Turbo Basic, you dont must open new channel to read a keyboard. TB have a opened (supposedly at channel #7) and have instruction to read "any" key :)

      example:
      10 GET KEY
      20 (doo something with KEY value :D)


      in this case, you have clear first channel and no frustraction ;)

      At last. I dont say it is easy ]:->
      Don't give up.

      Today is out. Tomorrow i must wake up at 4:30 :/ "Fast sleep" (i don't like this ;)

      Goodnight
      • 19: CommentAuthorw1k
      • CommentTime21 Apr 2010 12:04
       
      yesterday i trying GET KEY, but not work..
      IF K=("A") then..
      doesnt work
      • 20: CommentAuthormono
      • CommentTime21 Apr 2010 12:04
       
      Maybe better K=ASC("A")...?
      • 21: CommentAuthorw1k
      • CommentTime21 Apr 2010 13:04 zmieniony
       
      yes, you right, thank you:)
      and what about a looong text? i need stop text if screen is full and if i press key, text will be continue..



      loading txt files start at 5030
      • 22:
         
        CommentAuthorzilq
      • CommentTime21 Apr 2010 22:04 zmieniony
       
      w1k: Your GEY KEY solution i wrong, becouse KEY is a numeric variable (no text/character). When, if you try execute condition you give an error "Incompatibility type".
      10 GET KEY
      20 IF KEY=ASC("A") OR KEY=ASC("B") THEN ... (mono solution)

      or direct value (i thing it is faster method but more unreadable)
      30 if KEY=65 or KEY=66 THEN ...


      one more idea about read key and condition:
      10 DO
      15 ? "Choice [ABCD]: ";:GET KEY
      20 OPT=UINSTR("ABCD",CHR$(KEY))
      25 IF OPT
      30 ? CHR$(KEY):? "Good choice":EXIT
      35 ELSE
      40 ? "Wrong key, choice again"
      45 ENDIF
      50 LOOP
      55 ON OPT EXEC OPT_A,OPT_B,OPT_C,OPT_D
      OR
      55 ON OPT GO# OPT_A,OPT_B...
      or
      55 ON OPT GOTO 1000,2000,3000.... (*)
      or :)
      55 ON OPT GOSUB 1000,2000,3000.... (*)


      (*) this construction is not good in structural language like a TurboBasic, and is much slower than first two answer (EXEC and GO#)

      Mayby more complicated but, this idea have two, big upside: Very simble to expand and pressed key can by small letters or/and invers and works. :)

      Next answer. Viewing loong texts.

      hmm, this is much more complicated.

      Writen on fast, but work:
      0 GR.0:EOL=13
      1 DIM BUF$(10240),FN$(20)
      15 FN$="D:FILENAME.TXT":EXEC LOAD_TXT
      20 EXEC SHOW TXT
      999 END
      1000 PROC LOAD_TXT
      1005 BUF$(1)=CHR$(0):BUF$(10240)=CHR$(0):BUF$(2)=BUF$(1)
      1010 TRAP #END_LOAD:OPEN #1,4,0,FN$
      1015 BGET #1,ADR(BUF$),10240
      1020 # END_LOAD:CLOSE #1
      1025 TXTLN=INSTR(BUF$,CHR$(0)):BUF$=BUF$(1,TXTLN-1)
      1030 ENDPROC
      1099 --
      1100 PROC SHOW_TXC
      1110 PTXT=1:LN=0:X=0:Y=0
      1120 DO
      1125 IF BUF$(PTXT,PTXT)=CHR$(EOL)
      1130 X=0:Y=Y+1:LN=LN+1
      1135 ELSE
      1140 POS.X,Y: BUF$(PTXT,PTXT);:X=X+1:IF X>39:X=0:Y=Y+1:LN=LN+1:ENDIF
      1145 ENDIF
      1150 PTXT=PTXT+1:IF LN=23 OR PTXT>=TXTLN
      1155 POS.0,23:? "Press any key to continue or ESC";:GET KEY:LN=0:X=0:Y=0:? CHR$(125)
      1160 IF KEY=27 OR PTXT>=TXTLN THEN EXIT
      1165 ENDIF
      1170 LOOP
      1175 ENDPROC


      Uff...
      This code works ;) but it's no "demon of speed" ]:-> Write on speed and no time to think about speed :D ([url]http://www.end-of-world.join.pl/temp/w1k.tbx[/url] is file with this code)

      #1: Variable EOL is code of RETURN/ENTER (End Of Line) In my test file is 13. Atari RETURN equal 155!
      #2: To test this code, change filename in line 15!

      PS do "prowadzącego": Co jest nie tak z moim postem, że go tak sypie? Osobiście nie dopatruję się, żadnych błędów w tagach.