Solved

Arrays

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 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