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.

DarkBASIC Professional Discussion / Help with File Commands

Author
Message
Black Hydra II
22
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 2nd Dec 2003 02:09
I do not understand how these file commands are supposed to work. I have been using the DBPro demo for almost 60 days now and had already finished using the DB demo aswell as having C++ experience so I am not a noob to coding.

I made a text file (notepad) in my project folder and put

Open To Write 1, "cmpsts.txt"
Write String 1, "Hello!"

I am obviously doing this wrong. I looked in the file expecting to see "Hello!" and found nothing. I typed in

Open To Read 1, "cmpsts.txt"
Read String 1, hello$
PRINT hello$

again nothing! I know I am thinking it through wrong because the Read String command has no specification of What to read so I am assuming it just gets the entire file??

The demo has no real info on this topic and it would be very, very helpful if someone could point me in the right direction.

Thanks in advance.

"Damn had to remake account!" direct quotation from previous account.
Dr OcCuLt
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 2nd Dec 2003 02:16
i think you need to close the file be for it saved.
Stryder
22
Years of Service
User Offline
Joined: 1st Dec 2003
Location:
Posted: 2nd Dec 2003 03:03
Dr OcCuLt has the right idea. Use:

CLOSE FILE 1

Seems to work for me.
Black Hydra II
22
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 2nd Dec 2003 04:57
Sorry guys it doesn't work, thanks anyways though.

I opened the file and... again nothing inside.

On another note how do I locate a certain set of text?

If it would be easier, is there a tutorial on this subject? I am clueless in the area.

"Damn had to remake account!" direct quotation from previous account.
Neophyte
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 2nd Dec 2003 05:53
@Black Hydra II

"On another note how do I locate a certain set of text?"

I think that this is what you are looking for.

http://darkbasicpro.thegamecreators.com/?m=codebase_view&i=4ad6b06c93a873efcb2e3a6a1ac2f482
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 2nd Dec 2003 06:21
I know exactly what the problem is! In quite possibly one of the oddest aspects of the language, Open to Write will NOT work if the file already exist! That's right, this means you CANNOT open a file and only add a few lines. You have to DELETE the file before performing Open To Write, which creates the file for you. You would have ot ask someone more experianced then I as to why they did it this way.

Usermlsra - Causing Havoc with a Smile
Black Hydra II
22
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 2nd Dec 2003 06:37
Ummm...

Then how can I edit a file? I need to use it to save data from play to play. Will I have to load the data, save it under a variable then make the file and save it?

"Damn had to remake account!" direct quotation from previous account.
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 2nd Dec 2003 07:09
yes, it's one of the sillier things in dbp. Maybe Lee could incorporate a more robust set of File System commands (input, output, append etc

-RUST-
Neophyte
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 2nd Dec 2003 07:57
@Black Hydra II

"Then how can I edit a file? I need to use it to save data from play to play. Will I have to load the data, save it under a variable then make the file and save it?"

In a word, Yes.
ICERGB
23
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 2nd Dec 2003 09:49 Edited at: 2nd Dec 2003 10:27
Well now, tell me if this helps eh?

You will need to load the file(if it exists), and read all your current data into a string array - :

switch all your string array data as you would like it:

Then save all your array data:

(although I find that save array works better for many things-example not here; this is strictly read and write string arrays)

Ofcourse playing with it- is what makes it yours




Black Hydra II
22
Years of Service
User Offline
Joined: 26th Nov 2003
Location:
Posted: 3rd Dec 2003 00:05 Edited at: 3rd Dec 2003 00:12
hey thanks Iceburg.
A fellow canadian eh?

I'll go over your code to check it out but I think it will be good footing to learn the file commands...

Now I'll just have to get my friends encryption code...

EDIT - Hey Iceburg. Why did you put that dim temp$(100) at the top. It doesn't appear to be used at all in the program. I am just wondering its purpose seeing as temper$() seems to be holding all the data...

"Damn had to remake account!" direct quotation from previous account.
ICERGB
23
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 4th Dec 2003 06:04 Edited at: 4th Dec 2003 06:06
Yes ; know any DBpro users in ALberta?

Force of habit I think,
Everything below the "dim temper$(100)" gets ready to read more than one line of saved data/text from the temp.txt file;
Usually you would feed more than line into the temp.txt file at the beginning.

There is probably a more neat way to detect the end of data though.
Trowbee
23
Years of Service
User Offline
Joined: 12th Apr 2003
Location: United Kingdom
Posted: 5th Dec 2003 04:28
There is, with the FILE END command

I needed to append files before, so wrote a function to do it (not the neatest, but it gets the job done - fast)

It also returns the status of appending:
0 = did not work (file doesn't exist)
1 = worked
Jaze
22
Years of Service
User Offline
Joined: 20th Nov 2003
Location: Connecticut, USA
Posted: 5th Dec 2003 09:41
Nice Fudge - Works - But I'm dying how you had to load the whole file in to write it with appended data...ouch.

I'm tempted to start adding this kind of stuff myself - as file handling as well as a RDBMS interface could really help DarkBAsic I figure.

-=/Jaze/=-

Login to post a reply

Server time is: 2026-07-26 20:14:39
Your offset time is: 2026-07-26 20:14:39