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 Discussion / Writing numbers into files...

Author
Message
Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 9th Dec 2007 23:07
Okay I have worked on this for the past hour, write float, word, byte nor string (duh) doesn't work when I want to write a number in a file? How the heck can I do this?

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Dec 2007 23:12
If you want to write values to the file that you can view in notepad, then you'll want to write strings.



Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 9th Dec 2007 23:20
Thanks.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 9th Dec 2007 23:25 Edited at: 9th Dec 2007 23:26
Quote: "write float, word, byte nor string (duh) doesn't work when I want to write a number in a file"


It depends on what code you are using. We aren't mind readers!

But, Benjamin is right - go with writing numbers as strings as he demonstrated.

99 times out of 100, saving/loading problems are down to user coding errors and writing strings means you can open the file with a text editor and see what was written.

When loading numbers back in, use:

Read String 1,T$: NumVar = VAL(T$)

TDK_Man

JMScomp
17
Years of Service
User Offline
Joined: 9th Dec 2007
Location:
Posted: 10th Dec 2007 07:42
@TDK

I have different types of values saved in a file (i.e. String, Byte), but I can't use the same type twice. How do you save two string values in the same file?

Would it be something like this?
myValue = 123
myValue2 = 456

if file exist("myfile.txt") then delete file "myfile.txt"
open to write 1, "myfile.txt"
write string 1, str$(myValue)
write string 2, str2$(myValue2)
close file 1
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Dec 2007 20:24
As Windowskiller says, the number after Write String is the file (or channel) number.

Think of them as 'pipes' which connect your program to a disk file.

You can open a number of files on disk for reading or writing - each with a unique channel number. In the Read and Write commands, this number tells DB which file (pipe) to send the information down so it ends up in the correct file.

If you only have one file open, it's generally number 1 so all the commands refer to the number 1:



Str$ is a DB function which takes a numeric value and turns it into a string. VAL() is the DB function which takes a number in string format and turns it back to a numeric value.

TDK_Man

JMScomp
17
Years of Service
User Offline
Joined: 9th Dec 2007
Location:
Posted: 11th Dec 2007 03:41
Thanks, that helps a lot!
Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 23rd Dec 2007 03:25
Tdk and me pointed out some things in the thread below that you might find interesting.
http://forum.thegamecreators.com/?m=forum_view&t=116638&b=10

Login to post a reply

Server time is: 2025-06-02 10:13:30
Your offset time is: 2025-06-02 10:13:30