Creating a file etc

Technical Death
04-10-2003, 03:45 PM
Hey everyone, you could call me a visual basic newbie, but I'm getting there :)

Anyways, heres my question:

I'm making a game right now, and I want players to be able to SAVE their game for later use. I need to know how to create a file, and have my program read the text from it, and write to it as well. Plus, is there any tutorials on how to set up a file browser? Thanks everyone.

Squirm
04-10-2003, 03:54 PM
For a file browser, use the Microsoft CommonDialog control. There are many examples of its use here on the forum, and of course MSDN. For file manipulation, look into the Open Input Print Close Output statements, again there are many examples both here and in MSDN.

compugeek
04-10-2003, 03:55 PM
What game are you making? If you are just a beginner, try starting easier, unless it's a really simple game. (Even I don't know how to do a REAL game, yet. I'm gettin there...)
For your second question, to make a text file, use:
--
Open "C:\yourfile.txt" For Append As #1
--
Append will create a new file if it does not exist, and still have your program open it.

compugeek
04-10-2003, 03:58 PM
For the common dialog control, you can use statements such as ShowOpen or ShowSave, or something.

To open a file, use ShowOpen.
---
CommonDialog1.ShowOpen
---
This will show the file browser for Opening a file.

compugeek
04-10-2003, 04:05 PM
One last thing... to write text to a text file, place this after the "Open" stuff...

Write #1, 'Whatever you want to write goes here.
'To write specific text, put it in quotes: "Hello!"
'To write anything else, use the standard procedure,
'(example): Text1.Text

Technical Death
04-10-2003, 04:50 PM
The game pretty simple, but long. Its a puzzle/rpg, where you have to find objects in a picture and use them in other places.

I'm not that much of a beginner ;) Thanks for the help

Technical Death
04-10-2003, 05:25 PM
Sorry to bug you all again, I tried the Open "C:\yourfile.txt" For Append As #1, it worked, however, is it possible to get string values in there? For example, if variable "stName" is "Technical Death", how do I get it to make "C:\Technical Death.txt" thanks again...

compugeek
04-10-2003, 06:37 PM
Hmmm... that one is a tough one. I mean, I've never used it myself. Try this, though... :

Open "C:\" & stName & ".txt" For Append As #1

Hope this works. :)

**EDIT**
Sorry, I forgot the .txt part. The code is fixed now.

Technical Death
04-10-2003, 07:32 PM
Thx, it worked.

I can't see to recall information from the txt file. Any ideas?

SnakeChomp
04-10-2003, 09:01 PM
You need to open the file for Read access to be able to find out whats inside of it. Append access is only for writing additional data onto the end of the file. You can use Input # or Get # to read data, look those up on msdn. :)

Technical Death
04-11-2003, 05:08 AM
You need to open the file for Read access to be able to find out whats inside of it. Append access is only for writing additional data onto the end of the file. You can use Input # or Get # to read data, look those up on msdn. :)
Thx again.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum