Solved

read from external file

Posted on 2004-08-16
2
187 Views
Last Modified: 2010-04-23
hi,

i need to read from an external file.

the contents includes some delimters that i need to separate the string into parts.

eg for the string 123,123,123;456,456,456;

after separating, i need to add the parts into a ListView.

i keep on getting this error:
"
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
"

pls help..
0
Comment
Question by:TPoly
2 Comments
 
LVL 1

Accepted Solution

by:
ICTSYSTEMS earned 250 total points
ID: 11808423
From what i get, i guess you just want the numbers to be separated as individual pieces and put into the listview.  I made a quick test application, added a listview ListView1 and a button Button1 to the form and created the file with the numbers: C:\Temp\Test.txt.  To fill the listview, i double clicked Button1 which created an eventhandler for the Click event of the button.  Inside this method, i added following code and it worked just fine :

        Dim filInput As New StreamReader("C:\Temp\Test.txt")
        Try
            'get the file content
            Dim sContent As String
            sContent = filInput.ReadToEnd()
            'split the content
            Dim sParts As String()
            sParts = sContent.Split(";"c, ","c)
            'add each part to the listview
            Dim sPart As String
            ListView1.BeginUpdate() ' this tells the listview to stop drawing the content while you are filling it.
            ListView1.Items.Clear() ' clear old content
            For Each sPart In sParts
                ListView1.Items.Add(sPart)
            Next
            ListView1.EndUpdate() ' this tells the listview it can draw the content again.
        Finally
            filInput.Close()
            filInput = Nothing
        End Try

The BeginUpdate and EndUpdate make the listview (or any other component that visualizes data) stop rendering the content.  If you do not do this, the listbox will redraw itself every time you add one number to the list.  This of course, goes very fast with a small amount of numbers, but anyhow, it is a waste of time because you only want the data to be shown when all numbers are added to the listview.

If you only want the ";" characters to be separators and have items like 123,123,123 and 456,456,456 then you can drop the ","c argument of the Split() method.

Finally, because the default view of the viewport is mostly not what you desire, i wanted to tell that you can change the appearance of the content of a listview similar to the way you can change the view of files in Explorer: "small icons", "big icons", "details", "list", etc.  by changing the property "View" of the listview.

Hope this is what you want, if not, please give more information what you actually want to do, and please show us the code where the exception occurs.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 11808543
Hi TPoly:
It will help if you could provide us with a snippet of your code, showing the line that is producing your error.

Dabas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
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…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
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 …

948 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

21 Experts available now in Live!

Get 1:1 Help Now