 |
 |

06-09-2003, 11:00 PM
|
|
Newcomer
|
|
Join Date: Apr 2003
Posts: 15
|
|
Adding onto a text file, Instead of saving over.
|
Hi, i've been browsing the forums for several weeks now, thought i'd take a post with a problem that has been annoying me.
I'm trying to save onto a text file (i know how to normally do it). But instead, i want to add onto the end of the text file, not save over what is already there. My visual basic knowledge is pretty average, so don't wonder off on me
EDIT: Just to clarify what i meant, heres an explanation of the type of code i want to do:
Open text file
Write, after the whats already there: variable blah blah.
|
|

06-09-2003, 11:04 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
|
Open it for Append, not Output. Simple as that!
~MikeJ
|
|

06-09-2003, 11:08 PM
|
|
Newcomer
|
|
Join Date: Apr 2003
Posts: 15
|
|
|
Thanks for the quick reply! Could you give me a quick example of the code?
Open App.Path & "\example.txt" For Append As #1
Write #1, example
Close #1
Would that work?
|
|

06-09-2003, 11:09 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
Yes.
P.S.
Would post this reply faster, but only one post per minute so, ... 
|
|

06-09-2003, 11:14 PM
|
|
Newcomer
|
|
Join Date: Apr 2003
Posts: 15
|
|
|
Just one more question, what would be the best way to load all the individual entries into a list? Thanks for all the help so far, lifesaver dude!
|
|

06-09-2003, 11:20 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
K. Use this little bit of code. (Assumes entries are delimited with spaces)
Code:
'==VARIABLE DECLARES==
Dim ff as integer
dim tempbin as string
Dim sArray() as string
Dim x as long
ff = FreeFile
Open "file.txt" For Output as #ff 'open
Print #ff, tempbin 'save
Close #ff 'close
sArray = Split(tempbin, " ") 'splits on every space
For x = 0 to ubound(sArray)
List1.AddItem sArray(x)
Next
That ought to do it for you!
~MikeJ
|
|

06-09-2003, 11:37 PM
|
|
Newcomer
|
|
Join Date: Apr 2003
Posts: 15
|
|
Thanks for everything, i'll have a go at this as soon as i get on my vb computer. One more thing though (im really into this now  ). How do i open the browsing window so the user can browse text files?
|
|

06-10-2003, 12:58 AM
|
|
Newcomer
|
|
Join Date: Apr 2003
Posts: 15
|
|
I fixed that problem above myself. Need help with this now. Heres the code:
Code:
' Create a file
Private sub create_click()
Open App.Path & "\" + game.Text + ".txt" For Append As #1
Write #1, game.Text, developer.Text, publisher.Text, genre.Text, release.Text
Close #1
End Sub
' Open the file (from using common dialog)
Private Sub open_Click()
Open filename.Text For Output As #1
Print #1, game.Text, developer.Text, publisher.Text, genre.Text, release.Text
Close #1
End sub
For some reason, nothing happens when i click open...it creates the file alright. Just cant load the stuff into all the textboxes.
|
|

06-10-2003, 09:31 AM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
|
filename.text won't work because it is asking for the actual file name. So you need to copy and paste the code of where it is written to, and replace filename.Text with it.
~MikeJ
|
|

06-11-2003, 02:31 AM
|
|
Newcomer
|
|
Join Date: Apr 2003
Posts: 15
|
|
|
Did that, said "bad file mode" and selected the "Print" line.
|
|

06-11-2003, 04:51 AM
|
 |
Contributor
|
|
Join Date: Sep 2001
Location: Florida
Posts: 517
|
|
im doing the same thing, mine works fine, here it is:
Code:
'Write to the binary file
SaveData = Text1.Text
Open App.Path & "\Data\Test.dat" For Binary Access Read Write As FreeFile
Put #FreeFile - 1, , StrData
Close FreeFile - 1
Text1.Text = ""
'Save to the binary file
Open App.Path & "\Data\Test.dat" For Binary Access Read Write As FreeFile
StrData = String(LOF(FreeFile - 1), " ")
Get #FreeFile - 1, , StrData
Close FreeFile - 1
|
__________________
So let it be written. So let it be run.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|