Solved

Array skipping first record in flat file

Posted on 2004-10-14
5
318 Views
Last Modified: 2010-04-23
When I run the following code, it doesnt want to put the first record into element (0) it pits it into MyArray(1).
Can somone please take a look at this and let me know what I am missing.


       Dim FileName As System.IO.StreamReader
        Dim strOneLine, strFile As String
        Dim iCounter As Integer
        Dim MyArray As New ArrayList

        ofdFile.ShowDialog()
        FileName = New System.IO.StreamReader(ofdFile.FileName)
        strOneLine = FileName.ReadLine

        Do Until strOneLine = Nothing
            strFile = strOneLine & ControlChars.CrLf
            strOneLine = FileName.ReadLine
            MyArray.Add(strOneLine)
            txtNameResults.Text() += MyArray(iCounter) & ControlChars.CrLf
            iCounter += 1
        Loop
        FileName.Close()

thanks.
0
Comment
Question by:swilli6926
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:VBtorment
ID: 12310911
declare variable iCounter

Dim iCounter as Integer

iCounter=0

run code...
0
 

Author Comment

by:swilli6926
ID: 12310971
Yea I thought of that and I get the same result.
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12311725
Hi
In the first  add you put 2 lines of the file, try this,    

Do Until strOneLine = Nothing
         strOneLine = FileName.ReadLine
         MyArray.Add(strOneLine)
         str += Convert.ToString(MyArray(iCounter)) & ControlChars.CrLf
         iCounter += 1
         strFile = strOneLine & ControlChars.CrLf  <- After insert it
      Loop
0
 

Author Comment

by:swilli6926
ID: 12311835
Hmmm that didnt seem to make any difference.
0
 
LVL 10

Accepted Solution

by:
Hans Langer earned 50 total points
ID: 12311901
Upss. A mistake
Do Until strOneLine = Nothing
         MyArray.Add(strOneLine)
         str += Convert.ToString(MyArray(iCounter)) & ControlChars.CrLf
         iCounter += 1
         strOneLine = FileName.ReadLine '<- I forgot this line :P
         strFile = strOneLine & ControlChars.CrLf  
      Loop
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do sunrise and sunset times change with altitude 14 46
vb.net class 3 28
get combo value in class 5 24
DataGridView / get bound table name? 8 36
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question