Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Saving a file as a text document

Author
Message
Carrick
16
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 31st Jul 2008 10:13
I am trying to build a program that allows me to input certain variables then save them as a text document onto my computer. How od I do this?
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 31st Jul 2008 15:55 Edited at: 31st Jul 2008 15:56
Use the following commands:
OPEN TO WRITE File Number, Filename <-- This command opens a file for writing. You can now write stuff in the file.

WRITE STRING File Number, String <-- Use that if you want to write text to your file. Keep in mind that each time you call this command the text will be printed on a new line.

WRITE WORD File Number, Integer Number <-- Use that if you want to write an integer number... Keep in mind that this number will appear in strange symbols if you open the file in notepad. Write string is your best bet if you want to be able to read your text document in notepad.

WRITE FLOAT File Number, float value <-- Use that if you want to write a float to a file. This will also appear in weird symbols, so Write String would be best if you want to be able to read your files in notepd.

CLOSE FILE File Number <---This command will close the file. The file is done when you call this command. You can no longer write to it.

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 31st Jul 2008 20:16 Edited at: 31st Jul 2008 20:17
Remembering that you can't open to write a file which already exists.



The above code snippet will help round that

If you want to append data to an existing file you must load the data into DBP, then delete the file, then write the whole file again including the bit you wish to append.

Hope that helps

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jul 2008 21:36
... or use a replacement file plug-in, which I happen to have

Just follow the link:

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 31st Jul 2008 21:45
@IanM
Is there anything you haven't written a plug in for? Lol

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jul 2008 23:28
Sure. I only have 800+ commands in 30 plug-ins so far, so there's tons of room for more

Carrick
16
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 1st Aug 2008 21:16
alright but how do I make it so that I can have someone input something and then save that to a file so that it can be viewed as a text document?
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 2nd Aug 2008 11:58
This is maybe a little simplistic for what you want, but it should point you in the right direction.



Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Carrick
16
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 3rd Aug 2008 10:21
alright now is there a way to have it input something and then make a file with what I input and then still write stuff to it with more inputs?
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 3rd Aug 2008 14:41
It really depends on how much data we're talking about? Here are some suggestions, however most of these have already been suggested. See how you get on trying them.

1) Keep the variables in an array and save that when the program exits.

2) Load the file into an array, add the new variables to the array and then resave the file (this is what I do, altho it would be impractical with hundreds of mb of Data)

3) Download and try IanM's plug in.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Carrick
16
Years of Service
User Offline
Joined: 23rd May 2008
Location:
Posted: 5th Aug 2008 14:55
I kinda don't know how to do that... can you help me?
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 5th Aug 2008 21:50 Edited at: 5th Aug 2008 22:02
Here is an example that loads the file in and allows you to add more names and ages before exiting and saving.



Its maybe a bit clumsy, but it works and hopefully will help you in the right direction.

(Sorry for the Edit, that'll teach me for not testing the code properly)

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@

Login to post a reply

Server time is: 2024-11-24 23:13:53
Your offset time is: 2024-11-24 23:13:53