Results 1 to 3 of 3

Thread: Printing random access file

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    1

    Printing random access file

    If I have a random access file that contains a record at 1 and a record at 100 how do I code the application so only record 1 and record 100 print without 98 rows of squares representing the "nulls" in between? Following is the print code I am currently using:

    VB Code:
    1. Private Sub cmdPrint_Click()
    2.     Dim strFont As String, sngSize As Single
    3.     Dim strPS1 As String * 10, strPS2 As String * 30, strPS3 As String * 1
    4.     Dim intX As Integer
    5.        
    6.     strFont = Printer.Font
    7.     sngSize = Printer.FontSize
    8.     Printer.Font = "courier new"
    9.     Printer.FontSize = 10
    10.    
    11.     Printer.Print Tab(35); "Student Grades"
    12.     Printer.Print
    13.     Printer.Print
    14.     Printer.Print Tab(5); "Student Number"; Tab(30); "Student Name"; Tab(70); "Grade"
    15.     Printer.Print
    16.    
    17.     intX = 1
    18.     Do While Not EOF(1)
    19.         Get #1, intX, udtStuRec
    20.             strPS1 = udtStuRec.strStuNum
    21.             strPS2 = udtStuRec.strStuName
    22.             strPS3 = udtStuRec.strGrade
    23.             Printer.Print Tab(5); strPS1; Tab(30); strPS2; Tab(70); strPS3
    24.             intX = intX + 1
    25.         Get #1, intX, udtStuRec     'reads next record
    26.     Loop
    27.    
    28.     Printer.Print
    29.     Printer.Print
    30.     Printer.Print Tab(5); "End of report"
    31.     Printer.EndDoc
    32.     Printer.Font = strFont
    33.     Printer.FontSize = sngSize
    34.    
    35. End Sub

    Thanks,
    Wayne

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    process IntX the first time, and then add '99' to it to make it '100', and then process it the second time.

    Random access files can be accessed, well, randomly.

    for that matter, you could do 100 and then 1
    Last edited by dglienna; Jul 20th, 2004 at 12:55 AM.

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Just change the "Printer.Print" line to this:
    VB Code:
    1. If (strPS1 <> "") And (strPS2 <> "") And (strPS3 <> "") Then
    2.   Printer.Print Tab(5); strPS1; Tab(30); strPS2; Tab(70); strPS3
    3. End If


    doesn't two Get statements inside the loop cause problems? I would think that one should be removed,

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