-
Formatting a file in VB
I've been working on a project for a few days now and everytime it looks like I'm getting somewhere I hit a dead end. First let me explain the problem.
The general problem is that I have a file that I need to search through for a specific part. IE. Part 0 2, once that part is found I need to scan the components of that part for a specific component number. IE. COMP 4.
If that component is found, I need to remove it.
Sounds pretty easy so far eh?
Well here is where I get tripped up. I have two files that look like the following:
Main (this is the one being searched for the part number)
Code:
PART 0 1
COMP 3
COMP 5
COMP 6
PART 0 2
COMP 1
COMP 2
COMP 4
PART 0 3
COMP 98
COMP 99
Parts (this contains the search criteria)
Code:
PART 0 1 COMP 5
PART 0 1 COMP 6
PART 0 2 COMP 4
PART 0 3 COMP 99
What I have tried to do was basically get the PART number, run through the main file looking for that part number, then once its found search for the COMP number and remove it. I ran into so problems with that and abandoned it for now.
Now I thought I would scan through the main document, copy an entire PART section to a list, scan that list for component numbers and do a list.remove, then write them to a new file. However, I can't seem to get there with this idea, I don't know how to basically run the list against the Parts file successfully.
If any of you can think of a better way to do this, or even just help me with one of my ideas I'd much appreciate it. When I first took on this project it seemed straight forward and easy, but looks tend to be decieving.
Thanks guys
/phalse
-
Dont know how this got posted twice, Mods if you could delete one.
Thanks :P
-
Hi,
reminds me of another task of yours in July[1]. I would use a
similar strategy.
1. Read in the whole 'parts' - file in a SortedDictionary(of string, boolean)
2. Open an InputStream to 'main', an OutputStream to 'main_corrected'
3. Read a whole part from InputStream in a second SortedDictionary,
ut make sure not to add a line to that second SortedDictionary, which
should be removed (ie is part of the first SortecDictionary).
More detailed:
3.1. Read a line from InputStream: 'PART 0 1' and store it in a string strPart
3.2. Read the next line: 'COMP 3' and store it in another string strComp
3.3. Check whether strPart & vbTab & strComp is in the first SortedDictionary
(Here you may have to be a bit careful with the structure of the constructed string).
3.4. If not, add it to the second SortedDictionary
4. Write the corrected part (ie the second SortedDictionary) to the OutputStream
Cheers
[1] http://antionline.com/showpost.php?p=926981&postcount=8
-
Hey sec, your right, I thought I had referenced my other project back in July but I must have forgotten. I tried a similar approach, and ran into some deadends. I just jotted it all down on paper and think I have a solution.
I think, I'm going to write each section to a list, and then scan that list for components based on a comparison.
If that fails I'll be back for more information on your idea :). Thanks for the info it got me thinking, and I hope I figured it out.