 |
hotsports Level: Protégé
 Registered: 18-03-2006 Posts: 7
|
save data into a text file?
part of my project for school is saving text from some textboxs into a Textfile(notepad) ,which already has some data in it, without over writing the data.
how would i go about this?
the following code is what i have got so far, it saves the data i input to the text box but it writes over the data i already have in the textfile i want to save to.
Private Sub cmdsave_Click()
Close #1
Open ("C:\Documents and Settings\stephen fry\My Documents\michael\input.txt") For Output As #1
Print #1, text1.Text, Text2.text
Close #1
End Sub
- hotsports
[Edited by hotsports on 20-03-2006 at 05:39 PM GMT]
____________________________
[IMG]http://tinypic.com/m7b5tg.jpg[/IMG]
|
|
19-03-2006 at 03:48 AM |
|
|
pavol Level: Sage
 Registered: 11-07-2005 Posts: 68
|
Re: save data into a text file?
if you don't want it to overwrite the text already in the file then open the file not For Output but For Append. this will just add the text to the end of the file.
[Edited by pavol on 19-03-2006 at 10:00 AM GMT]
____________________________
"Intellectuals solve problems, geniuses prevent them."
-Albert Einstein
Pavol
|
|
19-03-2006 at 03:00 PM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: save data into a text file?
But if you want to insert data, not to append it, you will need to rewrite whole data again in new file.
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
20-03-2006 at 01:21 AM |
|
|
hotsports Level: Protégé
 Registered: 18-03-2006 Posts: 7
|
Re: save data into a text file?
quote: Goran wrote:
But if you want to insert data, not to append it, you will need to rewrite whole data again in new file.
and how would i do that?
____________________________
[IMG]http://tinypic.com/m7b5tg.jpg[/IMG]
|
|
20-03-2006 at 06:34 AM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: save data into a text file?
I dont know what is the structure of this file, but generally you should read file data into a string (aray), and when you want to add some data in some particular line, either:
1) start writing data to a new text file from the string array, and when you come to the point that you need to insert data, insert it, and the continue to write data from string array
2) the same as the above, only the target is not the file itself, but a new string array (or some other object that you will be storing data in).
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
20-03-2006 at 06:25 PM |
|
|
hotsports Level: Protégé
 Registered: 18-03-2006 Posts: 7
|
Re: save data into a text file?
nm mind guys i got a kid who is a wiz at vb to help me, heres the working code incase any1 was wondering
Dim counter As Byte, strline As String
If txtpatient.Text = "" Then
MsgBox "please fill in the patient number box", vbExclamation
ElseIf txtPN.Text = "" Then
MsgBox "please fill in the patient name box", vbExclamation
ElseIf txtAdress.Text = "" Then
MsgBox "please fill in the adress box", vbExclamation
ElseIf txtAd.Text = "" Then
MsgBox "please fill in the Admit Date box", vbExclamation
ElseIf txtroom.Text = "" Then
MsgBox "please fill in the room number box", vbExclamation
Else
patient(patientnumber).ID = txtpatient.Text
patient(patientnumber).name = txtPN.Text
patient(patientnumber).adress = txtAdress.Text
patient(patientnumber).admitdate = txtAd.Text
patient(patientnumber).room = txtroom.Text
Open App.Path & ("\patients.txt") For Output As #1
For counter = 1 To totalpatients
strline = patient(counter).ID & "#" & patient(counter).name & "#" & patient(counter).adress & "#" & _
patient(counter).admitdate & "#" & patient(counter).room & "#"
Print #1, strline
lbl2.Caption = totalpatients
Next counter
Close #1
MsgBox "file was saved successfully!", vbOKOnly, "successful save"
End If
____________________________
[IMG]http://tinypic.com/m7b5tg.jpg[/IMG]
|
|
21-03-2006 at 06:00 AM |
|
|
|
|
 |
 |