|
-
Jun 11th, 2004, 07:17 AM
#1
Thread Starter
Hyperactive Member
Working with text files
The text file I am working with is similar to a database. Long lines of comma delimited data. I want to write a program that get the first and third item from the file for display. And when its selected it I want to be able to edit the fifth item. I would import it to a database if it didn't need to be that text file. Can anyone think of a way to do the editing? I already know a way to get the certain item's I need, But if anyone has ideas I would be appreciative.
Thanks in advance.
-
Jun 11th, 2004, 10:06 AM
#2
Frenzied Member
Tool ..
Hope this helps ...
You'll probably need to convert the split string pieces to whatever data type you are working with (you don't say).
Snippet ...
Code:
Dim tempstr As String ' String to parse
Dim tempsplit(7) As String ' Array of string pieces
tempsplit = Split(tempstr, ",", 6) ' Look "Split" up in online help
' The following is the tricky part ...
' if there are fewer elements in the string than expected,
' this creates null defaults for the missing pieces.
' If you don't do this, an error in generated if you attempt
' to access "missing" pieces.
ReDim Preserve Tempsplit(6)
MsgBox(tempsplit(0), 0, "First Piece")
MsgBox(tempsplit(1), 0, "Second Piece")
' ... etc.
MsgBox(tempsplit(5), 0, "Remainder piece")
Good luck ...
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Jun 11th, 2004, 11:35 AM
#3
Thread Starter
Hyperactive Member
Thanks a bunch for your reply Webtest.
I thought of using a split, the only problem is in the text file I need to edit there are 2 sets of {}.
In those the ","'s need to be ignored. I did however figure it out with quite a bit more code than that.
There are 19 items per line, the 18th and 19th are in the {}.
I load an array, each array contains the whole text row.
I created a structure to hold the items, and a function to get the
items based on which commas they reside between.
I run the function 19 times, (don't know if thats a great idea or not) and fill the structure. I make the changes to the structure and I rebuild the string then overwrite that row in the array and use a streamwriter to save it all. Anyway, I'm not the brightest crayon in the box by any means so i get confused looking over it. All I know is it works now lol. Anyway if anyone else has an awkward problem like mine I will put my code here for ya. Thanks again and good luck
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
|