Solved

read from external file

Posted on 2004-08-16
2
190 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

808 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