|
-
Aug 25th, 2010, 04:02 PM
#1
Thread Starter
Hyperactive Member
TextFieldParser question
I am learning to use TextFieldParser to read a fixed width text data file.
It works great. I copied code below.
Question: How to stop at the end of each line because I need to add some code?
Using tf As New TextFieldParser(fileName)
tf.TextFieldType = FileIO.FieldType.FixedWidth
tf.SetFieldWidths(60, 30, 20) //three columns
Dim row As String()
While Not tf.EndOfData
row = tf.ReadFields()
For Each field As String In row
MessageBox.Show(field)
//need to add code in the end of each record, how?
Next
-
Aug 25th, 2010, 07:46 PM
#2
Re: TextFieldParser question
I don't really understand what you mean by "stop" at the end of each line. Do you mean you want to get some input from the user after each line? Please provide a clearer explanation of exactly what you're trying to achieve.
-
Aug 26th, 2010, 07:50 AM
#3
Thread Starter
Hyperactive Member
Re: TextFieldParser question
Sorry, here is more detail.
Dim row As String()
While Not tf.EndOfData
row = tf.ReadFields()
For Each field As String In row
MessageBox.Show(field)
//need to add code in the end of each record, how?
Next
After code above, data will show like below:
company1, location1, name1 (end of first record, I need to output to file1)
company2, location2, name2 (end of second record, I need to output to file2)
...
company10, location10, name10 (end of tenth record, I need to output to file10)
I need to determine where is the end of each record so that I can sent output file.
Last edited by aspfun; Aug 26th, 2010 at 07:55 AM.
-
Aug 26th, 2010, 06:36 PM
#4
Re: TextFieldParser question
So what you're actually saying is that you need to output each row to a separate file, correct? If so then that's exactly what you do. You simply add code inside the loop that writes the current row to a file.
-
Aug 27th, 2010, 07:43 AM
#5
Thread Starter
Hyperactive Member
Re: TextFieldParser question
Thank you.
Another question:
In order to get the value for each cell in the same row, I use code below using array.
Is it possible to do the same job from TextFieldParser only?
Dim Fields() As String
While Not tf.EndOfData
Fields = tf.ReadFields()
s1 = Fields(0)
s2 = Fields(1)
s3 = Fields(2)
End While
-
Aug 27th, 2010, 08:18 AM
#6
Re: TextFieldParser question
Evereything a TextFieldParser can do is in the documentation for the TextFieldParser class. If you want to read field values then that's how you do it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|