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 / Reading files not created with Write File

Author
Message
Gingerkid Jack
19
Years of Service
User Offline
Joined: 15th May 2005
Location: UK
Posted: 1st Nov 2009 12:32
Hello, I am creating a game which is set in a city with different vehicles and to handle all of the data (eg. speed,weight,acceleration etc) I have put all the files in a .ini file. However when I open to read this file and then print it. All of the data is screwed up and shows random characters. So is there a special way of reading user created ASCII code data? Thanks.

TheCleverGuyz
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 1st Nov 2009 13:55
How are you reading it?

Show us your code, and we'll show u where u'r going wrong

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Gingerkid Jack
19
Years of Service
User Offline
Joined: 15th May 2005
Location: UK
Posted: 1st Nov 2009 14:34 Edited at: 1st Nov 2009 14:34
Here is the code for the reading:


Here is the ini file contents:


Thanks

TheCleverGuyz
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 1st Nov 2009 15:53 Edited at: 1st Nov 2009 15:54
It definitively doesn't work like that.
The read commands just read raw byte values, sequentially from the opened file.
You can either use the read string command to read one line at a time and parse that yourself (the val function should come in handly here), or you might want to look into one of the ini file plugins that basically does what you are attempting.
There are several of those around (I think), but IanM's stuff is generally good; chances are you already have that particular plugin as its part of the Matrix1Utilities package.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Nov 2009 16:37
Quote: "So is there a special way of reading user created ASCII code data?"


If you want to write a file that is ASCII (and you can open and view it in Notepad for example), you need to use Write String.

Numeric variables can be converted to strings with Str$() before writing and converted back on reading with VAL().

Writing info purely as strings isn't necessarily the best method - just another method. It is however the best way to check that your file writing routines are saving the correct data.

On the other side of the coin, data files written this way can be opened and modified by the user. If this matters, you can convert your read/write routines to use non-string variables when it's all working.

Further Info

TDK

Login to post a reply

Server time is: 2024-11-16 09:20:04
Your offset time is: 2024-11-16 09:20:04