Solved

read from external file

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

24 Experts available now in Live!

Get 1:1 Help Now