• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

Array skipping first record in flat file

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
swilli6926
Asked:
swilli6926
  • 2
  • 2
1 Solution
 
VBtormentCommented:
declare variable iCounter

Dim iCounter as Integer

iCounter=0

run code...
0
 
swilli6926Author Commented:
Yea I thought of that and I get the same result.
0
 
Hans LangerCommented:
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
 
swilli6926Author Commented:
Hmmm that didnt seem to make any difference.
0
 
Hans LangerCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now