Page 1 of 1

Visual Basic game help

Posted: Thu Oct 30, 2003 5:07 pm
by Jeff
Hi. I'm trying to make a game, and i need to know how to load a file to a rich text box and keep the line breaks.
This is how it is now:
1) Jeff 2) Jeff 3) DRM
This is how I want it to be:
1) Jeff
2) Jeff
3) DRM

Thanks in advance.

Posted: Thu Oct 30, 2003 10:50 pm
by wardrich

Code: Select all

Private Sub [event name]()

Dim strNames As String
Dim strNames2 As String


Open "[filename.rtf]" For Input As #1
While Not (EOF(1))

Input #1, string1
Input #1, string2
input #1, string3
Wend

Close #1

End Sub


In your case, here's basically what it should look like...

Code: Select all

Private Sub [event name]()

Dim strNames As String
Dim strNames2 As String


Open "[filename.rtf]" For Input As #1
While Not (EOF(1))  
'While not EOF means WHILE NOT at the END OF THE FILE...

Input #1, string1
'In your case, string1 should be 1)Jeff
Input #1, string2
'In your case, string2 should be 2)Jeff
input #1, string3
'In your case, string3 should be 3)DRM
Wend

Close #1

End Sub


I think if you want the user to be able to click the choice and have it execute, your best choice would be to use a Listbox. Let me know if you need more help with this.

-Richard-

Posted: Fri Oct 31, 2003 12:46 am
by Splodginator
Add "\n" or (I think) "\n\l" or "\n\r", I forget which one is Windows.

Posted: Fri Oct 31, 2003 4:55 pm
by Jeff
I want it to be more then one file. So they can export and inport their high scores. I'm using a Common Dialog to do this.

Posted: Fri Oct 31, 2003 10:22 pm
by wardrich
to open multiple files, simply go

Code: Select all

Open "[filename.rtf]" For Input As #1 
Open "[filename.rtf]" For Input As #2
Open "[filename.rtf]" For Input As #3
While Not (EOF(1)) 

Input #1, string1 
Input #1, string2 
input #1, string3 
Wend 

Close #1 
Close #2
Close #3

End Sub

Just remeber to close each file that you open.


-Richard-

Posted: Sat Nov 01, 2003 11:02 am
by Jeff
k thanks

Posted: Sat Nov 01, 2003 10:09 pm
by wardrich
no problem. Just keep posting in here if you have any VB problems. I <i>should</i> be able to help you with it.

-Richard-

Posted: Wed Sep 22, 2004 2:31 am
by AngryDwarf
Splodginator wrote:Add "\n" or (I think) "\n\l" or "\n\r", I forget which one is Windows.
Im pretty sure thats only languages such as C,C++,C#,etc

Posted: Sun Sep 26, 2004 10:35 pm
by Jeff
Vb is Vbclrf, I think

Posted: Fri Oct 01, 2004 12:50 am
by barok_unlogged
it's bad practise to open files as #1 or #2 or #3. instead, dimension a variable for each open statement. right before open, you have this:

openvariable = FREEFILE

freefile will get the next open number, so if you have #1 being used by another open statment and you try to open another file as #1, the program will crash. by having openvariable = freefile, it should prevent crashing.

Posted: Fri Oct 01, 2004 10:04 pm
by wardrich
that's why you close it before another one tries to open it ;)

Posted: Sun Oct 03, 2004 12:36 pm
by barok_unlogged
freefile is da way to go. It just saves some trouble. :D