Solved

Arrays

Posted on 2004-10-14
5
420 Views
Last Modified: 2010-04-23
Take a look at the code below.

I am opening a text file and reading and counting the number of records.
---------------------------------------------------------------
        Dim FileName As System.IO.StreamReader
        Dim strOneLine, strFile As String
        Dim iCounter As Integer
       
        ofdFile.ShowDialog()
        FileName = New System.IO.StreamReader(ofdFile.FileName)
        strOneLine = FileName.ReadLine

        Do Until strOneLine = Nothing
            strFile += strOneLine & ControlChars.CrLf
            strOneLine = FileName.ReadLine
            iCounter += 1
        Loop

        FileName.Close()
----------------------------------------------------------------------------

what would be the best way to take the value of iCounter and create an array to store the results.
I am using iCounter to get the number of elements to set up my array.

thanks fo rthe help.
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 28

Expert Comment

by:iboutchkine
ID: 12308626
Dim arr(iCounter) as String' or whatever value you want to store in array
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 50 total points
ID: 12308697
why do't you use the Array class in .NET, and then you don't need to worry about sizing - the Array will automaticxally be of the correct size:

        Dim FileName As System.IO.StreamReader
        Dim strOneLine, strFile As String
        Dim iCounter As Integer
        Dim MyArray as New Array
       
        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)
        Loop

        FileName.Close()


AW
0
 

Author Comment

by:swilli6926
ID: 12308948
Arthur,

I get the following:

'New' cannot be used on a class that is declared 'MustInherit'.

What am I missing?
0
 

Author Comment

by:swilli6926
ID: 12308969
Actuall, if I use this:

Dim MyArray as New ArrayList

It seems to work.  Thanks!
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12314038
sorry about the confusion.  Glad to hear you figured it out.

Glad to be of assistance.

AW
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…

734 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