Results 1 to 4 of 4

Thread: Formatting a file in VB

  1. #1
    Join Date
    Apr 2006

    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)
    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)
    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

  2. #2
    Join Date
    Apr 2006
    Dont know how this got posted twice, Mods if you could delete one.
    Thanks :P

  3. #3
    Senior Member
    Join Date
    Mar 2004

    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


    [1] http://antionline.com/showpost.php?p=926981&postcount=8
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  4. #4
    Join Date
    Apr 2006
    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.

Similar Threads

  1. Forensic Process and Tricks
    By Tiger Shark in forum The Security Tutorials Forum
    Replies: 3
    Last Post: January 12th, 2007, 10:44 PM
  2. Writing to file in c++
    By Tedob1 in forum Other Tutorials Forum
    Replies: 4
    Last Post: October 15th, 2004, 06:31 AM
  3. The history of the Mac line of Operating systems
    By gore in forum Operating Systems
    Replies: 3
    Last Post: March 7th, 2004, 08:02 AM
  4. Solaris Hardening
    By R0n1n in forum *nix Security Discussions
    Replies: 3
    Last Post: November 20th, 2002, 02:20 PM
  5. Camouflage v1.2.1 The programme
    By Gbin@ryR in forum AntiOnline's General Chit Chat
    Replies: 8
    Last Post: February 28th, 2002, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts