Guys i have problem about fle handling..
i dont know howto update the text in the file.. or in the NOTEPAD

this is my code..


Private Sub cmdUpdate_Click()
Dim ndx As Byte
Dim tmp As String

Open App.Path & "\data.txt" For Output As #1

Write #1, txtname, txtaddress, txtphone.Text
Close #1

lstcontact.RemoveItem (lstcontact.ListIndex)
lstcontact.AddItem (Chr(34) & txtname & Chr(34) & "," & Chr(34) & txtaddress & Chr(34) & "," & Chr(34) & txtphone & Chr(34))

Close #1,


End Sub


that's the code guys.. when i run the program.. never be update at

the text file... it will Rewrite all in side the text file all datea will replace a new data...

hope some one help me thanks ^^:icon_smile:

Recommended Answers

All 2 Replies

First problem: you didn't use code tags. you can do that by typing (without the added spaces):
[ code=vb ]
' your vb code here
[ /code ]

Second Problem: it seems you are closing your file two times, but only opening it once... Tsk, Tsk.

Lastly, it seems that UPDATE is not the right word.... I think you mean "append", where it will write 1 line... then again another line. UPDATE would mean you are changing something already in the file.... here you simply want to add something to the file (or am I mistaken)? For this, you would probably want:

Private Sub cmdUpdate_Click()
Dim ndx As Byte
Dim tmp As String

Open App.Path & "\data.txt" For APPEND As #1 ' // yeah, for append
     Write #1, txtname, txtaddress, txtphone.Text
Close #1

lstcontact.RemoveItem (lstcontact.ListIndex)
lstcontact.AddItem (Chr(34) & txtname & Chr(34) & "," & Chr(34) & txtaddress & Chr(34) & "," & Chr(34) & txtphone & Chr(34))

End Sub

yeah your right .. but when i use append it will add again..like this


name: rejay
Address: USA
Phone : 123

other Data:

Name: berdos
Address: Canada
Phone:321


When i use append it will Appear like this ...

the file i want to Change..

Name: berdos
Address: China
Phone:321

This is inside the file in the Text

"rejay"," USA "," 123" / / First data
"berdos","Canada","321" / / Second Data
"berdos","China","321" // 3rd Data <---- this is my

problem when i use Append ....


my point is i want to change the previous File in the text like

this example ...


name: rejay
Address: USA
Phone : 123

other Data:

Name: berdos
Address: Canada
Phone:321

This is inside the file in the Text

"rejay"," USA "," 123" / / First data
"berdos","Canada","321" / / Second Data


so... i want to change the ADDRESS of Second Data... CANADA to CHINA like this..

name:berdos
Address: CHINA
Phone: 321


so the Output it will like this


This is inside the file in the Text

"rejay"," USA "," 123" / / First data
"berdos","CHINA","321" / / the NEW Second Data


see... . that's what i mean... i want to change the prevous data..

hope you understand... :icon_cheesygrin:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.