Solved

Array skipping first record in flat file

Posted on 2004-10-14
5
329 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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