Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Load TxT File  (Read 7368 times)

0 Members and 1 Guest are viewing this topic.

BooBoo

  • Amiga Guru
  • A600
  • ****
  • Karma: 3
  • Offline Offline
  • Posts: 168
Load TxT File
« on: February 19, 2008, 11:53:17 AM »

Hi I hope all is well in Amos land
I like to load and display a TxT file for a basic Menu
Basicly my txt file looks like
Quote from: Menu.TxT
1 Chaos Engine
2 Toki
3 Mercs
E.t.c
and my Amos Prog looks like
Quote from: Menu.Amos
Dir$="dh0:"
Open In 1,"Menu.TXT"
Input #1,A$
Print A$
Close 1
But this only displays the first line of my list is possible to display all the list?
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Load TxT File
« Reply #1 on: February 19, 2008, 05:16:10 PM »

Try this:

Code: [Select]
Dir$="dh0:"
Open In 1,"Menu.TXT"
While Not Eof(1)
  Line Input #1, A$
  Print A$
Wend
Close 1
Logged

BooBoo

  • Amiga Guru
  • A600
  • ****
  • Karma: 3
  • Offline Offline
  • Posts: 168
Re: Load TxT File
« Reply #2 on: February 19, 2008, 08:40:42 PM »

Thank You - yes this Works :) - Ive still got some problems and would appreciate further advice
This is the Code ive got so far
Code: [Select]
A=0
Pen 2 : Curs Off : Paper 0 : Cls 0 : Paper 0 : Hide
Pen 2 : Locate 0,0
Dir$="dh0:"
Open In 1,"Menu.TXT"
While Not Eof(1)
Line Input #1,A$
Print A$
Wend
Rem Print A
10 Pen 3 : Locate 1,A : Print ">"
Pen 2 : Locate 1,A+1 : Print " "
If A>0 Then Pen 2 : Locate 1,A-1 : Print " "
Do
If Jdown(1) Then Wait 5 : A=A+1 : Goto 10
If Jup(1) Then Wait 5 : If A>0 Then A=A-1 : Goto 10
If Fire(1) Then Goto 20
Loop
20Dir$="Dh0:"
B=A+1
Open Out 2,"Run"
Print #2,"Execute";B
Close 1
End

So the idea is it exports a simple TxT file called Run "Execute 2" which is then Executed by AmigaDos but the file its exports allways has a problem it wont execute corectly But I know if I create the same file in ED it works? any ideas?
Logged

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW
Re: Load TxT File
« Reply #3 on: February 19, 2008, 09:41:55 PM »

amiga txt files for sripts are slightly different to normal txt files... check its using a value of $50 (i think) to declare the end of a line - i know i've tripped over this a few times, with scripts refusing to run!
« Last Edit: February 19, 2008, 09:56:15 PM by Hungry Horace »
Logged
Quote from: KillerGorilla
because winuae is made of code and your amiga is made of stuff

BooBoo

  • Amiga Guru
  • A600
  • ****
  • Karma: 3
  • Offline Offline
  • Posts: 168
Re: Load TxT File
« Reply #4 on: February 20, 2008, 11:32:49 AM »

Yes I think your right I not sure how i can check this - But I had a similar problem when Editing my Startup-Sequence from WindowZ in both cases opening the Script with ED and re-saving with no changes solved the problem -Ive tryed adding "Set Input 10,-1" to my code but this only seems to help when loading a txt file not exporting so im still stuck?
Logged

BooBoo

  • Amiga Guru
  • A600
  • ****
  • Karma: 3
  • Offline Offline
  • Posts: 168
Re: Load TxT File
« Reply #5 on: February 20, 2008, 04:07:27 PM »

I found a way round it Im useing a tool from aminet called Feeder - End-of-line to LF ASCII text converter and it works in a Script so no GUI so all Ok - Big Thanks guys for the replys and help thanks to you I now have a Nice games Launcher for my A600  :)

http://aminet.net/util/conv/feeder.lha
Logged

cane

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 4
Re: Load TxT File
« Reply #6 on: June 29, 2008, 11:43:23 AM »

Try this:

Code: [Select]
Dir$="dh0:"
Open In 1,"Menu.TXT"
While Not Eof(1)
  Line Input #1, A$
  Print A$
Wend
Close 1

I'm already using this code, but is there some faster way of loading text files in string array?
Loading 20, 30kB text this way can take few seconds.
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Load TxT File
« Reply #7 on: June 30, 2008, 01:39:00 PM »

Does the text vary each time you run it?  If not, try converting the strings into Data statements in the code.
Logged

cane

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 4
Re: Load TxT File
« Reply #8 on: June 30, 2008, 09:29:12 PM »

Text files are the same, but there are quit a few of them, so Data is probably the best solution. But if I divide it in few parts than it loads in decent speed.
Logged

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: Load TxT File
« Reply #9 on: July 04, 2008, 08:16:43 PM »


Why not load them into an AMOS bank? It would take only a second or so to load them in and then you can display them as fast as the peek$ command will allow, unless you prefer using Chr$(Peek(address)).


Regards,
Lonewolf10

Logged

cane

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 4
Re: Load TxT File
« Reply #10 on: July 08, 2008, 04:32:15 PM »

I don't know how to do that  :-[, my knowledge of AMOS is basic. I'm satisfied with loading times when the text is broken in few files, but I'm more than willing to have a look if you have some source code regarding this problem.
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Load TxT File
« Reply #11 on: July 08, 2008, 11:35:11 PM »

When using the Peek$() function you can print an entire text file to the screen in one Print command.  The disadvantage of it is that you need to know the length of the file before you can print it.  Another disadvantage is that you have to know how much memory to reserve in the bank before you can load your data into it.

Here's a really fast way to load and print a text file:
Code: [Select]
` open the file to get its length
Open Input #1, "filename.txt"
` reserve enough memory in bank 15 to hold the file
Reserve As Work 15, Lof(1)
` we have the length now so we close the file
Close 1
` read the entire file in at once
Bload "filename.txt",15
` print the entire file at once
Print Peek$(Start(15),Length(15))
` free up the memory we stored it in
Erase 15
« Last Edit: July 08, 2008, 11:59:33 PM by SamuraiCrow »
Logged
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022