Reading the .txt file twice ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MiziaQ
    New Member
    • Nov 2007
    • 63

    Reading the .txt file twice ?

    The following code loads a sequential .txt file into an msflexgrid once a the second is clicked. The code for adding is correct. However it loads the file twice for some reason ? How do make it to display once ? Any suggestions ?

    [CODE=vb]Private Sub tabAdmin_Click( PreviousTab As Integer)

    If tabAdmin.Tab = 1 Then

    Open App.Path & "\deliveries.tx t" For Input As #12

    Dim oldRow As Long
    Dim lngRow As Long
    Dim lngCol As Long

    Dim strID As String
    Dim strPickupName As String
    Dim strPickupAdd As String
    Dim strPickupTel As String
    Dim strDelName As String
    Dim strDelAdd As String
    Dim strDelTel As String
    Dim strWoP As String
    Dim strDelPrice As String
    Dim strPriority As String
    Dim strPickupDate As String
    Dim strDelDate As String

    counter = 1

    Do Until EOF(12)
    Input #12, strPickupName, strPickupAdd, strPickupTel, strDelName, strDelAdd, strDelTel, strWoP, strDelPrice, strPickupDate, strDelDate
    MSFlexGrid1.Tex tMatrix(counter , 0) = ""
    MSFlexGrid1.Tex tMatrix(counter , 1) = strPickupName
    MSFlexGrid1.Tex tMatrix(counter , 2) = strPickupAdd
    MSFlexGrid1.Tex tMatrix(counter , 3) = strPickupTel
    MSFlexGrid1.Tex tMatrix(counter , 4) = strDelName
    MSFlexGrid1.Tex tMatrix(counter , 5) = strDelAdd
    MSFlexGrid1.Tex tMatrix(counter , 6) = strDelTel
    MSFlexGrid1.Tex tMatrix(counter , 7) = strWoP
    MSFlexGrid1.Tex tMatrix(counter , 8) = strDelPrice
    MSFlexGrid1.Tex tMatrix(counter , 9) = strPickupDate
    MSFlexGrid1.Tex tMatrix(counter , 10) = strDelDate

    MSFlexGrid1.Row s = MSFlexGrid1.Row s + 1

    For lngRow = MSFlexGrid1.Row s - 2 To MSFlexGrid1.Row Step -1
    For lngCol = 0 To MSFlexGrid1.Col s - 1
    MSFlexGrid1.Tex tMatrix(lngRow + 1, lngCol) = MSFlexGrid1.Tex tMatrix(lngRow, lngCol)
    If lngRow = MSFlexGrid1.Row Then
    MSFlexGrid1.Tex tMatrix(lngRow, lngCol) = "" 'Make the current row empty
    End If
    Next
    Next
    Loop
    Close #12
    End If

    End Sub[/CODE]
    Last edited by Killer42; Feb 22 '08, 12:38 AM. Reason: Added CODE=vb tag, adjusted indenting
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    I haven't been through this code in great detail yet, but I can verify that it is definitely not reading the file twice, unless you are calling it twice.

    What you should do is...
    • Check that the contents of the file are actually what you expect. Perhaps the data is recorded twice in the file.
    • Use the debugging tools built into VB to trace through the execution of the code to ensure you know exactly what it does.


    By the way, what's the purpose of the nested FOR loops?
    Last edited by Killer42; Feb 22 '08, 12:44 AM.

    Comment

    Working...