Solved

read from external file

Posted on 2004-08-16
2
206 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
[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 Comments
 
LVL 1

Accepted Solution

by:
IT Meetjesland 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 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