Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,076 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,771 people online right now. Registration is fast and FREE... Join Now!




how to update a file

 
Reply to this topicStart new topic

how to update a file

trila
6 Jun, 2008 - 06:40 PM
Post #1

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 1

Hi everyone who know about VB,i have a assignment to do,i have to save,delete,search and update.. i am not sure about my code in the button update ... this is my code ,wouls you mind show me my mistake ,thank you so much.



vb
  Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim line As String
Dim fields() As String
Dim objSR As StreamReader
objSR = New StreamReader(m_FILEPATH)
'create a temp
Dim objSW As New StreamWriter(Application.StartupPath & _
"\Temp1.txt", True)

line = objSR.ReadLine
Do Until (line Is Nothing)

fields = line.Split(Convert.ToChar(","))
If (fields(0) = txtUserID.Text) Then

Else
objSW.WriteLine(fields(0) & "," & fields(1) & "," & fields(2))
End If
line = objSR.ReadLine
Loop
objSR.Close()
MessageBox.Show("Do you want to update the file?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
MessageBox.Show("Please enter your new data.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
If (fields(0) = txtUserID.Text) Then

My.Computer.FileSystem.MoveFile(m_FILEPATH, CStr(fields(0) = txtUserID.Text))



objSR.Close()

MessageBox.Show("Your file already update.", " Delete Record", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
My.Computer.FileSystem.RenameFile(Application.StartupPath & _
"\temp1.txt", "user.txt")
Else
End If

End Sub

User is offlineProfile CardPM
+Quote Post

mensahero
RE: How To Update A File
6 Jun, 2008 - 07:28 PM
Post #2

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions

QUOTE


My.Computer.FileSystem.MoveFile(m_FILEPATH, CStr(fields(0) = txtUserID.Text))



Hello... I think you've posted in the wrong forum.. this should be posted on the vb.net forum..

Is the above code the only code your using to update the file? IDK vb.net but I think thats a .movefile method.. and its far from update.. I'm guessing that would probably move the file to another destination.. blink.gif


User is offlineProfile CardPM
+Quote Post

born2c0de
RE: How To Update A File
6 Jun, 2008 - 10:58 PM
Post #3

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,032



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Moved to VB.NET
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:13PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month