Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Arrays

Posted on 2004-10-14
5
Medium Priority
?
424 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

885 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