Results 1 to 4 of 4

Thread: sorting and merging of 2 sequnetial files

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    56

    sorting and merging of 2 sequnetial files

    Hello

    Pl Help me with this simple solution
    I want to merge two files How can i do it ?

    VB Code:
    1. OPEN "ADD.DAT" FOR INPUT AS#1
    2. DO UNTIL EOF(1)
    3. i% =i% + 1
    4. if i% > ubound(Names$) then redim preserve Names$(1 to i%)
    5. if i% > ubound(goals$) then redim preserve add$(1 to i%)
    6.  
    7. INPUT #1, Name$(i%), add$(i%)
    8. LOOP
    9. CLOSE #1

    Which displays
    "Ronaldo","Brazil"
    "David","UK"
    "Pele","Brazil"
    "Mardona","Argentina"
    "Doanald","SA"
    "Schnider","Germany"



    VB Code:
    1. OPEN "Goals.Dat" FOR INPUT AS#1
    2. DO UNTIL EOF(1)
    3. s$=s%+1
    4. if s% > ubound(Names$) then redim preserve Names$(1 to s%)
    5. if s% > ubound(goals$) then redim preserve goals$(1 to s%)
    6. INPUT #1, Names$(i%), goals$(i%)
    7. LOOP
    8. CLOSE #1

    Which displays
    "Ronaldo","10"
    "David","4"
    "Doanald","3"
    "Schnider","2"

    I want to merge above two files and get the result as
    "David","UK","4"
    "Doanald","SA","3"
    "Mardona","Argentina",""
    "Pele","Brazil",""
    "Ronaldo","Brazil","10"
    "Schnider","Germany","2"

    Pl Help

    Regards

    Samyo
    Last edited by si_the_geek; Jun 17th, 2006 at 08:04 AM. Reason: added vbcode tags for readability

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: sorting and merging of 2 sequnetial files

    Is this VB? If so, I'll move this to the classic VB forum (which will get more people looking at it).


    In order to merge the files you will need to read in the data from both files, but have it "lined up", so that the Goals$ array has the same order as the Names$ and add$ arrays.

    I would recommend changing the second part of the code to not read directly into the arrays - but instead use variables which you can use to compare against the values in the Names$ array (using a For/Next loop) to find the right row, or (if not found) add a new row to the array. You would then put the goal data into the same position in the goals$ array.

    When the data is in the arrays, you can simply write it out to a file.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    56

    Re: sorting and merging of 2 sequnetial files

    Already i've put in classic VBforums
    classic -----http://www.vbforums.com/showthread.php?t=411429
    still i've not got satisfied reply

    i dont want to use split function
    if you can help without using split fucntion it would be great
    Thanks
    Regards

    Samyo

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: sorting and merging of 2 sequnetial files

    As this is VB it belongs in a VB forum, not here.

    As you already have another thread there, I will close this one.

Posting Permissions

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



Click Here to Expand Forum to Full Width