Solved

read from external file

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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