Click here to Skip to main content
16,011,570 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: VB working with SQL... Pin
smjunior0912-May-09 9:50
smjunior0912-May-09 9:50 
GeneralRe: VB working with SQL... Pin
Christian Graus12-May-09 10:02
protectorChristian Graus12-May-09 10:02 
GeneralRe: VB working with SQL... Pin
smjunior0912-May-09 10:17
smjunior0912-May-09 10:17 
GeneralRe: VB working with SQL... Pin
smjunior0912-May-09 10:18
smjunior0912-May-09 10:18 
QuestionCompare Two Text Files Pin
vijay248212-May-09 4:47
vijay248212-May-09 4:47 
AnswerRe: Compare Two Text Files Pin
David Mujica12-May-09 5:20
David Mujica12-May-09 5:20 
GeneralRe: Compare Two Text Files Pin
vijay248212-May-09 21:33
vijay248212-May-09 21:33 
AnswerRe: Compare Two Text Files Pin
riced12-May-09 7:34
riced12-May-09 7:34 
Vijay
This is your algorithm reduced to the essentials.
Open OutputFile                                   'Using sw As StreamWriter
   Open InputFile                                 'Using sa As StreamReader
      Copy InputFile to CpyFile                   'i.e. to Similar1.txt
      Read InputFile into temp                    '1st header
      Set up p() array from temp
      Read InputFile into temp                    '2nd header
      While not at end of InputFile
         Read InputFile into temp                 'Data line
         Split temp                               'Into name, child, etc
         Open CpyFile                             'Using sa1 As StreamReader
            Read CpyFile into temp1               '1st header
            Set up p() array from temp            'Why? This has already been done
            Split temp1                           'Into name1, child1, etc
            Write Name1, child1, etc to OutFile   '1st header. Why not just write temp1 without splitting?
            Read and Write from CpyFile           '2nd header
            While not at end of CpyFile
               Read CpyFile into temp1            'Data line
               If (temp matches temp1) and created < created1 Then
                  Write temp1 to OutFile
               Else
                  Write temp to OutFile
               End If
            End While  'not EOF CpyFile
         Close CpyFile 'End Using
      End While 'not EOF InputFile
   Close InputFile 'End Using
Close OutPutFile 'End Using

There are some obvious problems - design not coding.
1. You write the header out each time you open the copy file. It should only be done once when you open the input file.
2. For each data line read from the copy file you write a line to the output file. Think about what happens when you read the first data line in both input and copy files. You cannot decide what to write until you have scanned all of the copy file for a match.
3. The scan of the copy file should begin at the next record after the one read from the input file. E.g. if you read the 10th data line from input file, the scan of copy file should start at 11th data line.
4. You have to open and close the copy file once for each data line in the input file. I don't know how many lines you will have in input file but that could be a lot of I/O.
5. The IF statement will be done once for each data line in copy file. But it's enclosing While loop will be done once for each data line in the input file. So if there are N data lines, it will be done N^2 times. For 10 data lines, that's 100 times; for 100 data lines that's 10,000 times. Performance for small test files might be ok, but large production files could be a problem.

I've not suggested solutions because I think this approach is not the right one. As I said before the solution lies in reading the input file into a list (or an array) and processing that.

Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis

GeneralRe: Compare Two Text Files Pin
vijay248212-May-09 21:31
vijay248212-May-09 21:31 
GeneralRe: Compare Two Text Files Pin
riced12-May-09 23:10
riced12-May-09 23:10 
GeneralMessage Closed Pin
13-May-09 0:15
vijay248213-May-09 0:15 
GeneralRe: Compare Two Text Files Pin
riced13-May-09 2:23
riced13-May-09 2:23 
GeneralRe: Compare Two Text Files Pin
vijay248213-May-09 2:44
vijay248213-May-09 2:44 
GeneralRe: Compare Two Text Files Pin
riced13-May-09 3:33
riced13-May-09 3:33 
Questionproblem with backup of data base Pin
nazimghori12-May-09 2:45
nazimghori12-May-09 2:45 
AnswerRe: problem with backup of data base Pin
Rajesh Anuhya12-May-09 3:06
professionalRajesh Anuhya12-May-09 3:06 
QuestionRe: problem with backup of data base Pin
nazimghori12-May-09 5:00
nazimghori12-May-09 5:00 
AnswerRe: problem with backup of data base Pin
EliottA12-May-09 5:12
EliottA12-May-09 5:12 
AnswerRe: problem with backup of data base Pin
Zaegra12-May-09 7:46
Zaegra12-May-09 7:46 
QuestionRe: problem with backup of data base Pin
nazimghori12-May-09 8:26
nazimghori12-May-09 8:26 
AnswerRe: problem with backup of data base Pin
EliottA12-May-09 8:30
EliottA12-May-09 8:30 
AnswerRe: problem with backup of data base Pin
Zaegra12-May-09 8:44
Zaegra12-May-09 8:44 
AnswerRe: problem with backup of data base Pin
DidiKunz12-May-09 21:22
DidiKunz12-May-09 21:22 
QuestionHow to change Regional language setting date format to dd/MM/yyyy ? Pin
Paramu197312-May-09 2:01
Paramu197312-May-09 2:01 
AnswerRe: How to change Regional language setting date format to dd/MM/yyyy ? Pin
Johan Hakkesteegt12-May-09 2:22
Johan Hakkesteegt12-May-09 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.