Solved

Arrays

Posted on 2004-10-14
5
417 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
  • 2
  • 2
5 Comments
 
LVL 28

Expert Comment

by:iboutchkine
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Actuall, if I use this:

Dim MyArray as New ArrayList

It seems to work.  Thanks!
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
sorry about the confusion.  Glad to hear you figured it out.

Glad to be of assistance.

AW
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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…

728 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

9 Experts available now in Live!

Get 1:1 Help Now