No announcement yet.

Printing columns and rows of data problem

  • Filter
  • Time
  • Show
Clear All
new posts

  • Printing columns and rows of data problem


    This is my first time using printer commands and I'm having trouble printing the row, column text from a grid.
    It overprints all the columns on each row. (prints each columns text over the previous one)
            Local R as Long, C as Long
            XPrint Attach Choose
            If Err = 0 And Len(XPrint$) > 0 Then
                    XPrint Color RGB(0, 0 ,0) ' Black
                    For R = 1 To 50
                            W! = 0
                            For C = 1 To 8
                                    XPrint MLG_Get(HWND_FORM1_Grid1, R, C);   'print text from grid location r, c and stay on same line
                                    W! = W! + SendMessage (HWND_FORM1_Grid1, %MLG_GETCOLWIDTH, C, 0)   'compute next x position
                                    XPrint Get Pos To x!, y!   'get the y value
                                    XPrint Set Pos (W!, y!)   'set the x and y position to print next column
                            Next C
                            XPrint   'drop to next line
                            If MLG_Get(HWND_FORM1_Grid1,R + 1,1) = "" Then Exit For   'if no text in next line then exit the loop
                    Next R    
                    XPrint FormFeed
                    XPrint Close
            End If
    Any help will be appreciated.

    Last edited by Gary Beene; 25 Jul 2014, 11:27 PM. Reason: Code: tags

  • #2
    You never seem to reset y!
    On each new row you'll need to increase y!


    • #3
      Hi Edwin,

      y should be increased by the lone XPrint statement executed after printing all the columns in a line. Then just before executing the Set Pos for the next line I do a Get Pos command which should get the new y.



      • #4
        It's working here

        The code you've posted works (modified to just print the letter 'A') using PB/Win 9.

        Have you tried a different printer?

        Also, for diagnosis, you may wish to write to a log the X! and Y! values after each call to XPRINT GET POSITION. Perhaps, log R,C,X!,Y! on each iteration to a text file. This might provide more information.

        You are correct, calling XPRINT by itself is meant to drop to the next line, and should increase your Y! (it does for me).

        P.S. For testing, instead of using paper, I'm printing to PrimoPDF and viewing the PDF file. Saves paper!


        • #5
          Hi Philip,

          It's good to hear it works for someone, if not me.

          My one and only printer is a HP 4215, couple years old, and I never had a problem with it using VB6.

          I wrote lots of the x data to a text file. It was all over the place. The W! value incremented as it was supposed to; in step with the column widths. But the x value sequentially increased then decreased all the way through the columns for every row.

          Yes, XPrint worked fine in my tests too. Rows incremented fine but all the columns printed near the left margin.

          I'll keep playing with it and hope, in the mean time, someone comes up with a reason for this behavior.



          • #6
            I got it

            I was misunderstanding the original post. I was thinking it wasn't progressing "down the page", but it sounds like it wasn't progressing over (right).

            Now that I understand the question better, it occurs to me that the MLG (my little grid) control is probably giving you width in pixels (relative to the screen).

            You'll either need to xprint scale, or multiply out to get the proper position on the printer, since it has WAY more resolution. Make sense?

            Of course, I haven't used MLG, this is just my theory.


            • #7

              That was it. Needed to set the Scale. Now it formats properly.

              Thanks for the help, Jim