Solved

Need an easy way to print my MSFlexGrid in VB6

Posted on 2014-11-17
9
366 Views
Last Modified: 2014-12-04
I need an easy way to print my MSFlexGrid in VB6.  The problem with my present setup is that it is repeating the first row on every page when it prints the flexgrid.  I would simply like to print the grid with the headings.

Currently I am using this command

FlexGridPrint Me.MSFlexGrid1, , , , , 1

Open in new window

0
Comment
Question by:al4629740
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40449170
where is the code for FlexGridPrint?

try this code: Print a FlexGrid control's data
0
 

Author Comment

by:al4629740
ID: 40451426
How would I call the routine?  Example please?
0
 

Author Comment

by:al4629740
ID: 40451437
Basically how would I execute this code:

Private Sub PrintFlexGrid(ByVal ptr As Object, ByVal flx As _
    MSFlexGrid, ByVal xmin As Single, ByVal ymin As Single)
Const GAP = 60

Dim xmax As Single
Dim ymax As Single
Dim X As Single
Dim c As Integer
Dim r As Integer

    With ptr.Font
        .Name = flxData.Font.Name
        .Size = flxData.Font.Size
    End With

    With flxData
        ' See how wide the whole thing is.
        xmax = xmin + GAP
        For c = 0 To .Cols - 1
            xmax = xmax + .ColWidth(c) + 2 * GAP
        Next c

        ' Print each row.
        ptr.CurrentY = ymin
        For r = 0 To .Rows - 1
            ' Draw a line above this row.
            If r > 0 Then ptr.Line (xmin, _
                ptr.CurrentY)-(xmax, ptr.CurrentY)
            ptr.CurrentY = ptr.CurrentY + GAP

            ' Print the entries on this row.
            X = xmin + GAP
            For c = 0 To .Cols - 1
                ptr.CurrentX = X
                ptr.Print BoundedText(ptr, .TextMatrix(r, _
                    c), .ColWidth(c));
                X = X + .ColWidth(c) + 2 * GAP
            Next c
            ptr.CurrentY = ptr.CurrentY + GAP

            ' Move to the next line.
            ptr.Print
        Next r
        ymax = ptr.CurrentY

        ' Draw a box around everything.
        ptr.Line (xmin, ymin)-(xmax, ymax), , B

        ' Draw lines between the columns.
        X = xmin
        For c = 0 To .Cols - 2
            X = X + .ColWidth(c) + 2 * GAP
            ptr.Line (X, ymin)-(X, ymax)
        Next c
    End With
End Sub

' Truncate the string so it fits within the width.
Private Function BoundedText(ByVal ptr As Object, ByVal txt _
    As String, ByVal max_wid As Single) As String
    Do While ptr.TextWidth(txt) > max_wid
        txt = Left$(txt, Len(txt) - 1)
    Loop
    BoundedText = txt
End Function

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:al4629740
ID: 40453986
not fully explained
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 40454543
did you to the link i sent you? just download the full project from the link beneath the code.
and try the code.

in summary, you just call!
PrintFlexGrid(ByVal ptr As Object, ByVal flx As MSFlexGrid, ByVal xmin As Single, ByVal ymin As Single)
ptr is the object on which you want to print, it can be a formname or just type Printer if you want to send it to the default printer
PrintFlexGrid Printer, Me.MSFlexGrid1, 1440, 1440

Open in new window

0
 

Author Comment

by:al4629740
ID: 40455711
I did do that....  I get an "object required" error on this line:

    With ptr.Font
        .Name = flxData.Font.Name
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40480541
did it work? or you're still getting the error? i just noticed ur comment!
0
 

Author Comment

by:al4629740
ID: 40481102
I still get the same error
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40481431
can you show me the code that you used? i tried the same code on my pc, and it works perfectly!
please provide me with the code you're using! (if you modified it), if not, send me how you're calling the function
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question