Solved

Array skipping first record in flat file

Posted on 2004-10-14
5
280 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
Comment Utility
declare variable iCounter

Dim iCounter as Integer

iCounter=0

run code...
0
 

Author Comment

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

Expert Comment

by:Hans Langer
Comment Utility
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
Comment Utility
Hmmm that didnt seem to make any difference.
0
 
LVL 10

Accepted Solution

by:
Hans Langer earned 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now