Solved

Array skipping first record in flat file

Posted on 2004-10-14
5
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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