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 / Variable file names?

Author
Message
Aiyon
17
Years of Service
User Offline
Joined: 4th Jan 2007
Location:
Posted: 5th Jan 2007 02:25
Hi there... i'm new, using darkbasic pro, and i'm trying to make a simple text-based program that can, as part of its function, read and write small text files. It's my first project. ^.^
Problem is, i want to have the program *create* said text files using a variable name.

Here's what i have so far on this matter:
Quote: "Input "What is the character name? ";CName$
if file exist (CName$.txt)
print "A character with that name is on file. View stats? (y/n)"
input "Choice: "; StatView$
else
print "No record exists for that character. Do you wish to add one? (y/n)"
input "Choice: "; NoRecord$
endif
if StatView$="y" then gosub ViewStats
if StatView$="n" then return
if NoRecord$="y" then gosub AddStats
if NoRecord$="n" then return
return

AddStats:
open to write 1, "CName$.txt"
write string 1, CName$
close file 1
return"


As you have probably guessed it quite happily creates a file called CName$.txt, which is not the desired result. And i'm at a loss as to what needs changing.


Any help would be appreciated.
Bozzy
18
Years of Service
User Offline
Joined: 10th Sep 2006
Location: Birmingham, UK
Posted: 5th Jan 2007 03:03 Edited at: 5th Jan 2007 03:06
Right, erm I think you need to put

Quote: "Quote: "Input "What is the character name? ";CName$
if file exist (CName$+".txt")
print "A character with that name is on file. View stats? (y/n)"
input "Choice: "; StatView$
else
print "No record exists for that character. Do you wish to add one? (y/n)"
input "Choice: "; NoRecord$
endif
if StatView$="y" then gosub ViewStats
if StatView$="n" then return
if NoRecord$="y" then gosub AddStats
if NoRecord$="n" then return
return

AddStats:
open to write 1, CName$+".txt"
write string 1, CName$
close file 1
return""



This just changes the CName$ variable position in the AddStats bit and also you need to add the +".txt" bit so it knows it's a text file

I think this should work

Bozzy
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Jan 2007 03:04 Edited at: 5th Jan 2007 03:05
for starters

if file exist (CName$.txt) should be
if file exist (CName$ + ".txt")


and


open to write 1, CName$ + ".txt"

Bozzy
18
Years of Service
User Offline
Joined: 10th Sep 2006
Location: Birmingham, UK
Posted: 5th Jan 2007 03:05
o yes and that
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Jan 2007 03:05
lol, cross-posting

Aiyon
17
Years of Service
User Offline
Joined: 4th Jan 2007
Location:
Posted: 5th Jan 2007 14:49
Hm. Now that i see it it makes so much sense from what i know of DBpro so far.

Thank you guys.

Login to post a reply

Server time is: 2024-09-25 15:15:36
Your offset time is: 2024-09-25 15:15:36