Results 1 to 4 of 4

Thread: Printing Problem HELP?!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    27

    Printing Problem HELP?!!

    I am trying to print out a table using the printer.print format. I am able top print it out but I am having problems trying to align the numbers so that it would actually look like a table. Could anyone help me please?


    Private Sub Form_Load()

    Dim x(19), y(19), J, I, H


    x(1) = -0.3327
    x(2) = -0.2728
    x(3) = -0.2129
    x(4) = -0.1538
    x(5) = -0.0946
    x(6) = -0.0184
    x(7) = 0.0639
    x(8) = 0.1712
    x(9) = 0.3216
    x(10) = 0.472
    x(11) = 0.6832
    x(12) = 0.8945
    x(13) = 1.1997
    x(14) = 1.5588
    x(15) = 1.9999
    x(16) = 2.6618
    x(17) = 3.3238
    x(18) = 3.4853
    x(19) = 3.5947

    y(1) = -59.9633
    y(2) = -49.1658
    y(3) = -38.3808
    y(4) = -27.7159
    y(5) = -17.0509
    y(6) = -3.3256
    y(7) = 11.5336
    y(8) = 30.8618
    y(9) = 57.9692
    y(10) = 85.0776
    y(11) = 123.1507
    y(12) = 161.2238
    y(13) = 216.2347
    y(14) = 280.9682
    y(15) = 360.4672
    y(16) = 479.7774
    y(17) = 599.0876
    y(18) = 628.1966
    y(19) = 647.9225




    For J = 1 To 2
    Printer.Print " HA Load on Lane No."; J
    Printer.Print " | Beam No. | Distribution Coeff. | L.L.Moment |"
    Printer.Print " ----------- --------------------- -------------"
    For I = 1 To 19


    Printer.Print " | " + Format$(I, "00") + " | " + Format$(x(I), "000.0000;-00.0000") + " | " + Format$(y(I), "000.000;-00.000") + " | "

    Next I
    Next J

    Printer.EndDoc
    End Sub

  2. #2
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: Printing Problem HELP?!!

    Set the font you want to print in a fixed-width font in which each character is the same width.

    Add the bold line into your code and you should be fine:
    Code:
    .....
    y(19) = 647.9225
    
    Printer.FontName = "Lucida Console"
    
    For J = 1 To 2
    ......



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  3. #3
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: Printing Problem HELP?!!

    In addition, if you want the fields to be the same total width as your header fields, add spaces for padding. Add String(n, " ") where n = the number of spaces you need for padding. See code in bold below:
    Code:
    Printer.FontName = "Lucida Console"
    
    For J = 1 To 2
        Printer.Print " HA Load on Lane No."; J
        Printer.Print " | Beam No. | Distribution Coeff. | L.L.Moment |"
        Printer.Print " ----------- --------------------- -------------"
        
        For I = 1 To 19
            Printer.Print " | " & Format$(I, "00" & String(6, " ")) & " | " & Format$(x(I), "000.0000" & String(11, " ") & ";-00.0000" & String(11, " ")) & " | " + Format$(y(I), "000.000" & String(3, " ") & ";-00.000" & String(3, " ")) & " | "
        Next I
    Next J
    
    Printer.EndDoc
    If you want to align the fields right, simply add the spaces in front of the values and if you want it centered, add half front and half after.

    They might be a more propper way to align them but the result is looking good too using string(n, " ").
    Last edited by Optional; Jan 25th, 2010 at 04:40 AM.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Printing Problem HELP?!!

    you can also use printer.currentX to set the position on a line
    if you put a ; at the end of a print statement, the next print will be on the same line
    vb Code:
    1. printer.print " | " + Format$(I, "00")  ;
    2. printer.currentX = 250
    3. printer.print "| " + Format$(x(I), "000.0000;-00.0000") ;
    4. printer.currentx = 550
    5. printer.print " | " + Format$(y(I), "000.000;-00.000") + " | "
    the above should all print on the same line with columns set by the value of currentX

    i did not test this, so they may overprint , just increase (or decrease) the values for currentX, as required
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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