December 19th, 2007, 09:36 PM
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)
Parts (this contains the search criteria)
PART 0 1
PART 0 2
PART 0 3
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.
PART 0 1 COMP 5
PART 0 1 COMP 6
PART 0 2 COMP 4
PART 0 3 COMP 99
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.
December 19th, 2007, 09:38 PM
Dont know how this got posted twice, Mods if you could delete one.
December 20th, 2007, 09:33 AM
reminds me of another task of yours in July. I would use a
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).
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
If the only tool you have is a hammer, you tend to see every problem as a nail.
(Abraham Maslow, Psychologist, 1908-70)
December 20th, 2007, 04:25 PM
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.
By Tiger Shark in forum The Security Tutorials Forum
Last Post: January 12th, 2007, 10:44 PM
By Tedob1 in forum Other Tutorials Forum
Last Post: October 15th, 2004, 07:31 AM
By gore in forum Operating Systems
Last Post: March 7th, 2004, 08:02 AM
By R0n1n in forum *nix Security Discussions
Last Post: November 20th, 2002, 02:20 PM
By Gbin@ryR in forum AntiOnline's General Chit Chat
Last Post: February 28th, 2002, 05:52 PM