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 / Opening and editing "existing" text (*.txt, *.ini) files

Author
Message
Abson
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location: United States
Posted: 23rd Nov 2002 21:18
I'm very new to programming, I've never used anything other than this and so far, even though I still stuck (always will, lol), I'd like to learn! Having said that, here is my issue that I have a feeling isn't possible

I want to open an existing txt file, actually it's an ini file, edit a particlar row / column in it and then close it, is this possible? I can get Darkbasic Pro to make a new file, I can put something in it and close, but I really want to edit an existing file and make changes to any row / column. If this is possible, would someone mind posting the source? I have what I've been able to do so far below:

1 line of text within the ini:

open to write 1, "c:\windows\desktop\test.ini"
write string 1, "This is a test"
close file 1

2 lines of text within the ini:

open to write 1, "c:\windows\desktop\test.ini"
write string 1, "This is a test"
write string 1, "Test 2"
close file 1

All this works fine. What I want to be able to do is have that file already existing and just make changes to it, for example, have the end result go from:

This is a test
Test 2

To:

Hello
This
Is
Another
Test

etc...

If anyone can help me with this, I would greatly appreciate it, thank you! If it's not possible, then I guess I'm out of luck, I don't want to have to resort to something like Visual Basic / Studio just to edit an existing ini / text file, hehe.
Luke
22
Years of Service
User Offline
Joined: 29th Aug 2002
Location: United States
Posted: 23rd Nov 2002 23:12
well, I only know DB, not DBP not they are a lot alike.
if you just want to edit a string or something, then well, if the file is small (like under 1000 lines or so) then you could load all the strings into an array, edit the strings, the write the file, 'cause I don't think there is an "open to edit" command. So do this:
1)load all the strings into an array
2)edit strings
3)write file
if you need help doing any of this then ask, 'cause I like to help .

www.CyberLuke.com
Abson
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location: United States
Posted: 24th Nov 2002 01:10
Hey Luke,

I wasn't aware of the array command, so I will mess with this. In order for me to load an array, I have to create one first, this seems to be using the DIM? command. Since the file I want to edit already exists, I'm going try and copy it in to an array file automatically somehow, that'll save me some time, and if I can't, (which I know I won't be able to do no doubt, lol), I'll just write a seperate program that I can use to make this array that I need, then I'll go back to my main program and load it from there if I can. I'm sure I'll be back here, lol. Thanks a lot!

Mike.

Login to post a reply

Server time is: 2024-11-23 18:16:27
Your offset time is: 2024-11-23 18:16:27