Solved

Arrays

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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