forums

TNT Basic Forums > Programming Q&A
Files and the Esc key
< Last Thread     Next Thread >
Author
Thread        Post A Reply

03-09-2006 04:21

Posted by:
Stu

Location:
USA

Click Here to Email Stu   Find more posts by Stu

Just a couple of quick questions:
What can I specify under type in the Create File command that will allow it to be edited in another program with a separate language and still be read by TNT?
Also, can the escape key be used in user-made apps, or is it reserved for blacking out the screen and showing the menu bar? I tried setting actions with the if pressed(53) condition, but they won't execute. I believe that 53 is the proper number for the escape key, so I'm just wondering about that. Thanks in advance.

03-09-2006 23:14

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Couple of ideas...

What sort of files do you want to save? If it's just plain ASCII text you can use the TEXT type, anything more elaborate than that and you're going to have to go to the internet and find specific format specs for the files you wish to produce, and try emulating them as DATA files.
There's nothing from stopping you saving HTML, XML or CSV files for example, as long as you know how to code them in the first place, it's just a text file with a specific format.
Binary files are a bit more complex in TNT as you can't write anything smaller than 4 bytes (although you can bit shift and perform logic ops to create composite 'byte strings' as longs). I don't know if the DATA type adds any specific formatting (though I will check this out...), but if it doesn't you should (in theory) be able to replicate any file type for which you know the format.

As far as the escape key goes:

disable break
int rawKey, scanCode

repeat
rawKey=Keyboard Raw Key
scanCode=Raw Key Scancode(rawKey)
until scanCode=53

print "Use 'Disable Break' and it works, but pressed(53) doesn't!"

Have fun...

Danny (nods)

03-11-2006 03:44

Posted by:
Stu

Location:
USA

Click Here to Email Stu   Find more posts by Stu

Thanks for the reply, and the escape key issue is pretty well resolved. I'm still having trouble with the file, maybe because I've failed to understand how I should use the syntax.
Here's what I've got:

if file exists("Z_Prefs")
prefs=Open File("Z_prefs",true,"TEXT","Text")
for q = 1 to 5
hs[q] = File Read Int(prefs)
next q
Close File prefs
else
prefs=Create File("Z_Prefs","TEXT","Text")
file Write prefs, 5000
file Write prefs, 4000
file Write prefs, 3000
file Write prefs, 1000
file Write prefs, 500
end if

It will work fine as long as I don't edit the named file externally. However, that's a problem, because I need to be able to do just that. I'm pretty sure that my prblem is still in "type", since it exits with error when I edit the file, saying that it is the wrong type.

03-11-2006 09:53

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

No, you are doing it right...

Chances are that the App you are using to edit the file externally is changing the Finder's type and / or creator flags, and TNT is just being a bit pedantic about reading it back in. I noticed that when I created the file it had one icon, but once edited the icon changed to a generic, blank one. Something happened in there somewhere... I'll have a rummage through the source and get back to you on this one.

Radical theory: You could always write a utility in TNT to edit your files until we can get this sorted. Just an idea.

Watch this space...

Danny (nods)

03-11-2006 22:56

Posted by:
Stu

Location:
USA

Click Here to Email Stu   Find more posts by Stu

Yeah, you're right about the file changing. I just tried to edit it with a text editor I made in another language and it still works. It must've just been the other program I was using.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.