Question Text File is deleted.....

rjcj10

New member
Joined
Mar 26, 2009
Messages
1
Location
Makati, Philippines
Programming Experience
1-3
Good Morning

I am making a simple program on writing on a text file. The writing and reading of the text files works fine but i am having trouble with the file. It is being deleted everytime the 3 intervals on the loop. it seems that it bypasses the FILE COPY operation. here is code i'am using. thank you very much.

VB.NET:
Do While objReader.Peek <> -1

                    TextLine = objReader.ReadLine()

                    TempTxt = TextLine.Split(vbNewLine)

                    Text = TextLine.Split(",")

                    For Num2 = 0 To UBound(TempTxt)



                        For Num = 0 To UBound(Text)

                        Next



                        If Text(2) = ErrFile Then

                            TempTxt(Num2) = TextLine

                            ErrWrite = (Text(0) & "," & Desc & "," & ErrFile.ToString & "," & Err.Erl.ToString & "," & "," & Date.Today & "," & "Error not Fix!")

                            objWriter.WriteLine(Trim(ErrWrite))

                            Numcon = 1

                            If objReader.Peek <> 0 = True Then

                                objWriter.Close()

                                objReader.Close()

                                System.IO.File.Delete(FILE_NAME)

                                System.IO.File.Copy(FILE_NAME2, FILE_NAME)

                                System.IO.File.Delete(FILE_NAME2)

                                System.IO.File.Create(FILE_NAME2)

                                Exit Sub

                            End If

                        Else

                            objWriter.WriteLine(Trim(TempTxt(Num2)))

                            If objReader.Peek <> 0 = False Then

                                If Numcon = 1 Then

                                    objWriter.Close()

                                    objReader.Close()

                                    System.IO.File.Delete(FILE_NAME)

                                    System.IO.File.Copy(FILE_NAME2, FILE_NAME)

                                    System.IO.File.Delete(FILE_NAME2)

                                    System.IO.File.Create(FILE_NAME2)

                                    Exit Sub

                                Else

                                    ErrWrite = (Str(Text(0) + 1) & "," & Desc & "," & ErrFile.ToString & "," & Err.Erl.ToString & "," & "," & Date.Today & "," & Text(6))

                                    objWriter.WriteLine(Trim(ErrWrite))

                                    objWriter.Close()

                                    objReader.Close()

                                    System.IO.File.Delete(FILE_NAME)

                                    System.IO.File.Copy(FILE_NAME2, FILE_NAME)

                                    System.IO.File.Delete(FILE_NAME2)

                                    System.IO.File.Create(FILE_NAME2)

                                    Exit Sub

                                End If

                            End If



                        End If

                    Next

                Loop
 
Last edited by a moderator:
Back
Top