Results 1 to 4 of 4

Thread: Merging 2 Sequential files

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    56

    Merging 2 Sequential files

    sorry an error in previous thread
    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$(s%), goals$(s%)
    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
    "Ronaldo","Brazil","10"
    "David","UK","4"
    "Pele","Brazil",""
    "Mardona","Argentina",""
    "Doanald","SA","3"
    "Schnider","Germany","2"

    Pl Help

    Regards

    Samyo





    i

  2. #2
    Addicted Member
    Join Date
    Jan 2002
    Posts
    157

    Re: Merging 2 Sequential files

    Hi Samyo

    I hope this helps
    Try this out

    VB Code:
    1. Open "Palyers.dat" for OutPut as #3
    2. OPEN "ADD.DAT" FOR INPUT AS#1
    3. While not eof(1)
    4. c%=c%+1
    5. INPUT #1, Name$(c%), add$(c%)
    6. Wend
    7. CLOSE #1
    8.  
    9. OPEN "Goals.Dat" FOR INPUT AS#2
    10. While not eof(1)
    11. s$=s%+1
    12. INPUT #1, Names$(s%), goals$(s%)
    13. Wend
    14. CLOSE #1
    15.  
    16. For j% = 1 to c%
    17.         For k% = j% +1 to c%
    18.     if  Names$(j%) > Names$(k%) then
    19.  
    20.       tmp$ = Names$(k%)
    21.       Names$(k%) = Names$(j%)
    22.       Names$(j%) = tmp$
    23.  
    24.       tmpadd$ = add$(k%)
    25.       add(K%) = add(j%)
    26.       add(j%) = Tmpadd$
    27.    end if
    28. next k%
    29.  
    30.  
    31. For m% = 1 to s%
    32.         For n% = m% +1 to s%
    33.     if  Names$(m%) > Names$(n%) then
    34.  
    35.       tmp$ = Names$(k%)
    36.       Names$(k%) = Names$(n%)
    37.       Names$(n%) = tmp$
    38.  
    39.       tmpgoal$ = goal$(k%)
    40.       add(K%) = add(n%)
    41.       add(n%) = Tmpgoal$
    42.    end if
    43. next m%
    44. WRITE #3, Names#(j%), add$(j%) Goal$(j%)
    45. Next j%
    46. Close#3
    Regds
    Samf

  3. #3
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Merging 2 Sequential files

    check this link:

    How to merge two text files
    CS

  4. #4
    Lively Member Agilaz's Avatar
    Join Date
    Jun 2006
    Posts
    98

    Re: Merging 2 Sequential files


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