473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Reading the .txt file twice ?

63
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
Feb 21 '08 #1
1 1679
Killer42
8,435 Expert 8TB
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?
Feb 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: deko | last post by:
Is there a way to avoid opening and closing the file "viscount" twice in this code: <?php $file = 'viscount.txt'; if ($counter = @file ($file)) { $line = each($counter); if (!$counter) {...
2
by: | last post by:
Hi, I was using the Reader class to read a binary file and I noticed that there is no PeekByte and also its not optimised when using Peek and Read in sequence. If the .Peek is called its read...
2
by: Brian Ward | last post by:
First: sorry as a relative newbie for previously not including code. My question: Reading C++ books I almost always find programs such as the one below give the following type of code for reading...
7
by: DJP | last post by:
Hi, I need to read a file programmatically until end of file. My logic is as follows: while(!feof(Fp)) { fgets(readLine,10000,Fp);
20
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
3
by: syntax | last post by:
hi, i want to read a file using fread() in equal chunks through a for loop so that at the last call i dont get error..which way, i should read it? let me give an example, suppose i have 100...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
1
by: arkangel | last post by:
Hi it is in C# I am unsing the typical while (line=sr.ReadLine!=NULL) , for reading a text file but what i wan to do is to read the line twice I want to read in the while condition...
7
by: ramana | last post by:
I'm wondering if someone could point me to the flaw in the following code that uses the while(!FP.eof()) condition to read the input data. This condition is reading the last data point of the file...
1
by: CodeSeeker | last post by:
I have an application, which uses pop3 to read the messages from the mailbox, and it has been working fine for so many year. We recently have started changing this application to use java mail IMAP 4...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.