Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading the .txt file twice ?

Member
 
Join Date: Nov 2007
Posts: 56
#1: Feb 21 '08
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 ?

Expand|Select|Wrap|Line Numbers
  1. Private Sub tabAdmin_Click(PreviousTab As Integer)
  2.  
  3. If tabAdmin.Tab = 1 Then
  4.  
  5.   Open App.Path & "\deliveries.txt" For Input As #12
  6.  
  7.   Dim oldRow As Long
  8.   Dim lngRow As Long
  9.   Dim lngCol As Long
  10.  
  11.   Dim strID           As String
  12.   Dim strPickupName   As String
  13.   Dim strPickupAdd    As String
  14.   Dim strPickupTel    As String
  15.   Dim strDelName      As String
  16.   Dim strDelAdd       As String
  17.   Dim strDelTel       As String
  18.   Dim strWoP          As String
  19.   Dim strDelPrice     As String
  20.   Dim strPriority     As String
  21.   Dim strPickupDate   As String
  22.   Dim strDelDate      As String
  23.  
  24.   counter = 1
  25.  
  26.   Do Until EOF(12)
  27.     Input #12, strPickupName, strPickupAdd, strPickupTel, strDelName, strDelAdd, strDelTel, strWoP, strDelPrice, strPickupDate, strDelDate
  28.     MSFlexGrid1.TextMatrix(counter, 0) = ""
  29.     MSFlexGrid1.TextMatrix(counter, 1) = strPickupName
  30.     MSFlexGrid1.TextMatrix(counter, 2) = strPickupAdd
  31.     MSFlexGrid1.TextMatrix(counter, 3) = strPickupTel
  32.     MSFlexGrid1.TextMatrix(counter, 4) = strDelName
  33.     MSFlexGrid1.TextMatrix(counter, 5) = strDelAdd
  34.     MSFlexGrid1.TextMatrix(counter, 6) = strDelTel
  35.     MSFlexGrid1.TextMatrix(counter, 7) = strWoP
  36.     MSFlexGrid1.TextMatrix(counter, 8) = strDelPrice
  37.     MSFlexGrid1.TextMatrix(counter, 9) = strPickupDate
  38.     MSFlexGrid1.TextMatrix(counter, 10) = strDelDate
  39.  
  40.     MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
  41.  
  42.     For lngRow = MSFlexGrid1.Rows - 2 To MSFlexGrid1.Row Step -1
  43.       For lngCol = 0 To MSFlexGrid1.Cols - 1
  44.         MSFlexGrid1.TextMatrix(lngRow + 1, lngCol) =  MSFlexGrid1.TextMatrix(lngRow, lngCol)
  45.         If lngRow = MSFlexGrid1.Row Then
  46.           MSFlexGrid1.TextMatrix(lngRow, lngCol) = "" 'Make the current row empty
  47.         End If
  48.      Next
  49.     Next
  50.   Loop
  51.   Close #12
  52. End If
  53.  
  54. End Sub

Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#2: Feb 22 '08

re: Reading the .txt file twice ?


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?
Reply