Results 1 to 3 of 3

Thread: Checking a File

  1. #1

    Thread Starter
    Addicted Member icemanmt78's Avatar
    Join Date
    May 2000
    Posts
    142

    Angry

    I am using the following code to loop through three files and process the data from each. I don't want to change the core functionality of this code.

    Open sSummaryFileName For Append As #iSummFile
    For count = 1 To 3
    iTextFile = FreeFile
    Open sFilename(count) For Input As #iTextFile
    'Opens First Input File
    Print #iSummFile, sHeader(count)
    'Prints Header in Output File

    Do Until EOF(iTextFile)
    m_sReadString iTextFile
    'Read in each Line and format
    m_sWriteString iSummFile
    'Write the formatted line to the Output File
    Loop
    Close #iTextFile
    Next count

    Close #iSummFile

    As You can See I loop through each file at a time and then deal with the contents of each file.

    My problem is as follows:
    I print a header into iSummFile which changes for each of the three text file i am reading. If one of these files doesn't exist I still want the code to print a header into my final file. In other words if a file doesnt exist i only want to print the header before moving on to the next file and processing the data.

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You will be printing the header no matter what, so print these first.

    Then check to see if the file exists using the Dir$() function. If the file exists then carry on as noraml, else it will skip the file.

    Code:
    Open sSummaryFileName For Append As #iSummFile
    
    For Count = 1 To 3
      iTextFile = FreeFile
      
      'print the headers no matter what
      Print #iSummFile, sHeader(Count)
      
      'if the file exists then open it and read / write
      If Dir$(sFilename(Count)) <> "" Then
        
        'Opens First Input File
        Open sFilename(Count) For Input As #iTextFile
        
      
        Do Until EOF(iTextFile)
          m_sReadString iTextFile
          'Read in each Line and format
          m_sWriteString iSummFile
         'Write the formatted line to the Output File
        Loop
      
        Close #iTextFile
      End If   'If Dir$(sFilename(Count)) <> "" Then
    Next Count
    
    Close #iSummFile
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Addicted Member icemanmt78's Avatar
    Join Date
    May 2000
    Posts
    142

    Wink Cheers

    Your the Boy!

    Thanks

    Iceman

    code:

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