losing data when writing into a txt file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itrdbg
    New Member
    • Jul 2008
    • 3

    losing data when writing into a txt file

    hi all,

    I have posted this problems already, i am posting it again as i have not asked the question. My problem is I have a data around 24320 lines in a txt file. when i am transforming each value and writing it into another text file i am able to write only around 22000, the other values are not writen into the file I am not able to find the solution as I do not know the reason why it is happening so. Please suggest a solution for this problem my code is

    //code starts:
    Dim abArray()
    Dim t As Long
    Dim x
    count = 0



    fName = "data\" & "TT1" & ".TXT"

    Open fileN For Input As #3

    On Error GoTo ErrorHandler

    Do While Not EOF(3)

    Line Input #3, x

    Counter = 0

    Open fName For Input As #14

    Do While Not EOF(14) ' Outer loop.
    'If t = 1790 Then
    ' MsgBox ("ok")
    'End If
    Counter = Counter + 1

    Line Input #14, y

    If x = y Then

    ReDim Preserve abArray(t)

    abArray(t) = Hex(Counter)

    t = t + 1
    count = count + 1

    Exit Do ' Exit inner loop.

    End If


    Loop
    Close #14

    'If count > 30160 Then
    ' MsgBox ("ok")
    'End If


    Loop

    Close #3

    fileNK = file & "1" & ".txt"
    Open fileNK For Append As #13

    p = 0
    For t = LBound(abArray) To UBound(abArray)
    p = abArray(t)
    g = Len(p)
    If g = 1 Then
    Print #13, "0" & p

    Else
    ' If t = 22312 Then
    'MsgBox ("ok")
    'End If

    Print #13, abArray(t)

    End If
    Next t

    Close #13

    Set pnlX = Form1.StatusBar 1.Panels(3)
    pnlX = "Generation of Family Keys Complete"

    ErrorHandler:
    On Error Resume Next

    Code Ends//

    thankyou
  • janders468
    Recognized Expert New Member
    • Mar 2008
    • 112

    #2
    I wasn't able to quite follow all of your code but it sounds like you are wanting to open one file and copy that to another. My feeling is that you may be experiencing troubles with hardcoding the file numbers, but I could be off. The below subroutine will do what you want. Typically if your going to use this method of opening files you want to use the freefile function to determine a free file number and ensure that you properly close all of those file handles. If you don't then it won't write the buffered characters to the underlying file. There are many methods you could go about doing this, but I tried to keep this close to the IO methods you were using. Let me know if this is what you are looking for.
    Code:
    Sub CopyFile(FileFrom As String, FileTo As String)
        Dim intFile As Integer
        Dim strBuffer As String
        intFile = FreeFile
        Open FileFrom For Input As #intFile
        strBuffer = Input(LOF(intFile), #intFile)
        Close intFile
        intFile = FreeFile
        Open FileTo For Output As #intFile
        Print #intFile, strBuffer
        Close intFile
    End Sub

    Comment

    Working...