Results 1 to 14 of 14
  1. #1
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596

    File I/O - Writing page headers.

    Hi,

    I am reading data from a text file and selecting some lines to write to another text file.

    I have a line count going.

    After 65 lines, I want to write a page header consisting of 5 lines of text.



    There are 5 places in the code that I can reach the 65 lines at and require a page header.

    I want a page header routine in one place that I can 'call' it from.

    I created something like this in my code as a page header 'routine' [based on the 'On Error GoTo . . .' model]:
    Code:
    'Code . . .
    'Code . . .
    If LineCount = 65 Then
    GoTo WritePageHeader
    
    WritePageHeader:
    'Code to write the 5 Header lines to the output Text file . . .
    If I DO use this - how do I get back to where I was in the code when I redirected to the 'WritePageHeader' label?
    Is this a bad way to do this?
    What is the most efficient way to achieve what I'm trying to do?

    I'd appreciate any suggestions.

    Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Don't use GoTo.

    Call a Sub or Function procedure.

    Put the WritePageHeader code in an independent procedure and call it.

    You have a looping structure to read/write lines?

    You want to write this header every 65 lines?

    Assume LineCount cannot be 0.

    If LineCount Mod 65 = 0 Then
    WritePageHeader
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Thanks, June! Appreciate it.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    June,
    Why do you suggest
    If LineCount Mod 65 = 0 Then
    instead of just
    If LineCount = 65 Then
    ?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    I don't have the complete procedure to evaluate so I made an assumption you have a counter variable that will increment beyond 65 and that you want this header every 65th line.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Your assumption is correct. I DO have a line counter variable - and it is named LineCount.

    However, my question is - why not just say 'If LineCount = 65 Then WritePageHeader . . .' instead of what you suggested - 'If LineCount Mod 65 = 0 Then'.
    I'm just curious to know why you suggest using the 'Mod'.
    Thanks!

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Because when the line counter hits 130, 195, 260, 325 do you want the header lines to write? Or is there a loop within which the line counter is set back to 1 so it never exceeds 65? Adjust the conditional line accordingly.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Aaah . . . got it. I'm re-setting my LineCount at each new page so it never goes past 65.
    Thanks, June! Appreciate your help.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Do you really want the header after the 65th line?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Yes - has to be 65 lines per page because that is the standard that we are following.
    The text file will get uploaded into a 3rd party reporting package [Synergy] and our standard is to have all our Synergy reports with 65 lines per page [including the Page Headers].
    So - when I hit the 65th line, I will write the 65th line & then write the Page Header for the new page.
    I know you're probably thinking of something that I may be missing when you ask the question - may I ask what it is?

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Do you need the header on first page before the first line of data, followed by 65 (or 64) lines of data then repeat?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Yes - I need the header on the first page followed 60 lines of data [the Header is 5 lines].

    I write the very first Page Header [Page 1] before I enter my Loop.
    In the Loop:
    I read a line -> increment the line count ->
    if it is 65, I [process . . . and] write the line and then write the Page Header lines -> then set the line count to 5 -> & then read the next line.
    if it is NOT 65 yet - I [process . . . and] write the line -> & then read the next line.
    I haven't completed this code yet and verified that I am writing everything out correctly & that my line counts are all good - still working on it.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Could maybe include the header in the loop and write it when the counter is 0, something like:

    While text file not end (whatever that condition would be like)
    For i = 0 to 60
    If i = 0 Then
    'write header
    Else
    'read/write other data
    'move to next line of source file
    End If
    Next
    Wend

    Do you have to exclude some lines in the source file from being written to new file?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Yes - there are lines that I have to exclude.
    The source data has essentially 4 types of data - of which I need only 1.
    1. Header lines [I've created my own so . . . ] - Need to Exclude.
    2. Type "A" [I'm just naming it that] - which I need - may have unspecified number of rows of data - Need to Include all rows.
    3. Type "B" [I'm just naming it that] - which I need - may have unspecified number of rows of data - Need to EXclude all rows.
    4. Type "C" [I'm just naming it that] - which I need - may have unspecified number of rows of data - Need to EXclude all rows.

    All 4 row types are identified by a word [Let's say "H" {for Header}, "A", "B", & "C"] starting at position 21 on the line.
    I'm checking each line for that identifier - and setting flags to tell me which type of row type I'm in - till I hit the next row type . . .

    Thanks for your help & I hope you have a good weekend!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Headers that span more than a page
    By herbc0704 in forum Reports
    Replies: 1
    Last Post: 12-30-2011, 06:21 AM
  2. Control Page Headers with VBA?
    By FL_Boy in forum Reports
    Replies: 3
    Last Post: 12-22-2011, 03:49 PM
  3. Sub report page headers
    By rahayes in forum Reports
    Replies: 3
    Last Post: 11-11-2011, 04:21 AM
  4. Page Break in Report Headers
    By JonathanT in forum Reports
    Replies: 8
    Last Post: 06-30-2011, 10:37 PM
  5. Too many page headers for one report?
    By Swilliams987 in forum Reports
    Replies: 0
    Last Post: 02-14-2011, 11:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums