Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading text file contents 1

Status
Not open for further replies.

missedit

Technical User
Apr 25, 2005
21
GB
I have a text file in a folder -same path as movie say \notes

I need to take the word that is in that file and display it in a text box on the screen. I may have different text files but when the projector is burnt to disk the correct file will be with the movie in that instance.

Would be grateful if anyone can help here. Just getting to grips with lingo.

Many thanks.

Phil
 
found
on startmovie me
gtitle = new(Xtra "FileIO")
openFile(gtitle, the moviepath &"course.txt", 1)
member("contents").text = readFile(gtitle)
closeFile(gtitle)
gtitle = 0
end
But can you read more than 1 file at a time
 
No - computer can do only one thing at a time!

What you can do is repeat the process, for example:
--
on startmovie
global gtitle
gtitle = new(Xtra "FileIO")
repeat with i = 1 to 100
openFile(gtitle, the moviepath & "course" & i & ".txt", 1)
member("contents" & i).text = readFile(gtitle)
closeFile(gtitle)
end repeat
gtitle = 0
end
--
This will read 100 external text files named "course1.txt", "course2.txt" … "course100.txt" and write their text into 100 members.

Kenneth Kawamoto
 
Actually this doesn't work.

It keeps stopping at this line
openFile(gtitle, the moviepath & "course" & i & ".txt", 1)
says it expects a text string.

Thanks for any help here

Phil
 
The script definitely works. Do you actually have text files named "course1.txt", "course2.txt", etc? I think you don't. If you don't, the script stops at this line (not the line you specified):
--
member("contents").text = readFile(gtitle)
--
If there's no file, readFile(gtitle) returns VOID, which is not a string therefore the script error alerts "String expected".

To verify this, put some error checking routines such as:
--
on startmovie
global gtitle
gtitle = new(Xtra "FileIO")
repeat with i = 1 to 100
openFile(gtitle, the moviepath & "course" & i & ".txt", 1)
tText = readFile(gtitle)
tErrorCode = gtitle.status()
if tErrorCode < 0 then
tErrorStr = gtitle.error(tErrorCode)
alert("FileIO error:" && tErrorStr)
else
member("contents" & i).text = tText
end if
closeFile(gtitle)
end repeat
gtitle = 0
end
--
Do you get the error massage saying, "File not open"?

Kenneth Kawamoto
 
Thanks it now works - everything was wriiten as you said and files were in correct place - only problem is that when run it as a projector get a script error on screen - but it works. Also new to MX2004 how do you stop close max buttons appearing - used to be a check box for that.

Many thanks for all your help
 
I wrote repeat with i = 1 to 100 just to show the concept. If you have 3 external text files then it should be i = 1 to 3 otherwise it will result in error when i = 4, as there is no such file as "couse4.txt".

Another thing is you have to have corresponding text cast members "countents1", "contents2" etc. Otherwise it causes error. (You can dynamically create text members on the fly using new if you wish.)

As for the close box etc, go to Display Template under Movie's Property Inspector. Check boxes are there.

Kenneth Kawamoto
 
I have used this for getting text files and works really well...

on beginsprite me

withcompliments = getNetText (the moviepath & "text\withcompliments.txt")
member("withcompliments").text = nettextresult(withcompliments)

end

hope it helps :) and has no Xtras...
 
Two questions:

1. How would you go about reading those text files from a floppy disk rather than the CD? (assuming that the files have been saved onto a floppy disk previously)

2. When using 500ml's solution about [tt]getNetText[/tt] is there a tried and tested way of checking whether an internet connection exsits when the movie starts (sets a global variable to 0 or 1), and then these lines of code are only executed if that global variable is set to 1?

Thanks,
Tim
 
1. It is the same whether you're reading a file from a CD, floppy, USB Stick or whatever. Use BuddyAPI baFindDrive to find a drive letter where the specific file exists.

2. getNetText won't require any internet connection if it is used to retrieve a text from a local file. However #internetConnected property of the environmentPropList will tell you if the machine has the connection:
--
put _system.environmentPropList.internetConnected
-- #online

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top