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 / read .txt file, swap letters, rewrite to file (DBP)

Author
Message
RebirthAnime
22
Years of Service
User Offline
Joined: 11th Oct 2002
Location:
Posted: 1st Apr 2004 04:43
Hey..I'm trying to find a way to read a .txt file in DBP and then have it swap out each letter/symbol with whatever it's set to equal (ie, a = 10) and then have it rewrite the entire thing back to the .txt file (a new one, yes..can't write to an already existing one) I've done something similar before with a video information checking program, but I'm not really finding a way to do this too well, I don't know enough about the read byte/word/long commands and such, can anyone give me a helping hand?
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 1st Apr 2004 04:56 Edited at: 1st Apr 2004 04:56
I had some difficulty myself when I was trying to write a high score out to a file to be read back into the game at run time - I ended up writing the value out as a string and converting it back to a number when I read it back in again (source included).

I am sure someone more experienced will come along with the answer but this will work in the meantime.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Apr 2004 07:46
so the text file would contain 'a' and you want to convert that into '10'?

"eureka" - Archimedes
RebirthAnime
22
Years of Service
User Offline
Joined: 11th Oct 2002
Location:
Posted: 1st Apr 2004 07:52
yeah, think encoding, I want it to see the letter "a" as if typed in a text file, then I want it to write all that text back into a .txt file with all the letters replaced with the coresponding replacement number/symbol
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 1st Apr 2004 11:44 Edited at: 1st Apr 2004 11:47
Give this a try (attached code snippet) and see if it is close to what you are after.

It has an array containing the letter ("a" e.t.c.) and a corresponding code for it (for simplicity, I have used the ASCII value of the letter, less 96 - so a = 1, b = 2 e.t.c.).

It writes out a string to a text file in coded format, and then reads it back, decodes it, and displays the result on the screen.

It only handles lower case letters in it's present form but it's only an example to hopefully point you in the right direction.

Edit : I made an error in the comments :



Should read :



Apart from that it's okay

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Apr 2004 21:44
Be careful with that though. Upper case and lower case have different ASCII values. Best idea is to read all the characters in as one case. upper$(), lower$()

"eureka" - Archimedes
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 1st Apr 2004 23:11
Aye this is quite true - to be fair I did mention the fact the code I presented only handled lower case letters.

RebirthAnime
22
Years of Service
User Offline
Joined: 11th Oct 2002
Location:
Posted: 2nd Apr 2004 03:23
hmm..I'm actually rather lost.:/..mostly just with the first set of things where you were making the letters into ascii and such, but I'm gona fool with it more and see if I can manage to get it to encode the way I want
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 2nd Apr 2004 03:45
Ah sorry about that RebirthAnime - it was just a quick way of loading the array with letters and corresponding numbers.

Here's a version without all that messy ASCII stuff :



RebirthAnime
22
Years of Service
User Offline
Joined: 11th Oct 2002
Location:
Posted: 2nd Apr 2004 05:04
ah, that helps a little, sorry..as much as I love to program and get an ungodly amount of ideas on games to make and lil programs and such I'm a horrible programmer, and it takes me a while to figure anything out
RebirthAnime
22
Years of Service
User Offline
Joined: 11th Oct 2002
Location:
Posted: 2nd Apr 2004 05:09
sorry for being a neusance..I think I know how to encode it using your thing to the amount I want, but now it's not decoding anything and I don't really understand what all the stuff in your decode function means/does, such as len or all the (element,2)...all that :/..I'm gona keep fooling with it as usual
RebirthAnime
22
Years of Service
User Offline
Joined: 11th Oct 2002
Location:
Posted: 2nd Apr 2004 05:54
ok..I can get it to encode to the file and print correctly using 9 numbers for each letter, ie ("000000009" = a) , but it won't decode or print the decoded properly..I've been fooling with changing the numerical values in the dim statement at the top and the letter + 1 thing in the decode..none of which is working..am I missing something here where it's trying to read a lesser amound of integers for the letter than what I have or something?
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 2nd Apr 2004 16:54 Edited at: 2nd Apr 2004 16:55
It's no bother at all - just ask away anytime - glad to help.

If you increase the number of digits in your codes then you need to make a small adjustment to both the encoding and decoding routines to take into account the number of digits in your coded version of the letters.

The same program but with 9 digits per code would be :



Four changes were made :

1) The coded versions of the letters as declared in the array were changed to nine digits ("10" became "000000010" for example)

2) The coded version of the " " was changed from "__" to "_________" because to keep the coded string uniform for later decoding, a space needs to be written out the same length as the coded version of the letter so "_________" = nine spaces.

(Note : I have used "_" do denote spaces to preserve the format)

3) The For..Next loop in the decoder code was changed from Step 2 to Step 9 to reflect the new number of digits in the code (9).

4) The part that decoded each letter was changed from Mid$(String$, Letter) + Mid$(Strings$, Letter + 1) to a quick For..Next loop to concatenate all 9 digits of the code - it could have been written as :



It would have achieved the same thing only with more typing (I'm lazy so I prefer to type as little as I can get away with!)

RebirthAnime
22
Years of Service
User Offline
Joined: 11th Oct 2002
Location:
Posted: 2nd Apr 2004 21:22
hey! thanks a lot! this is gona help me out great!

Login to post a reply

Server time is: 2024-11-26 12:35:51
Your offset time is: 2024-11-26 12:35:51