Solved

how to execute this code - Argument not optional

Posted on 2014-11-19
4
148 Views
Last Modified: 2014-11-19
I have the following code that shows how to print from a flexgrid in VB6.   The only problem is that I don't know how to call this routine in my command button on my form.  

I get the error "argument not optional."  Can someone explain why that happens

Private Sub Command4_Click()
Call PrintFlexGrid
End Sub

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
Comment
Question by:al4629740
  • 2
4 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 40454039
don't you have a minimum of description on this method? where did you copy it from?

it looks like ptr could be a printer object but that I am not sure.

flx is your flexgrid control for sure.

xmin and ymin looks like margin, so maybe you can try with 0 to start with

That would look something like:
Call PrintFlexGrid(YourPrinterObject, theNameOfYourMSFlexGridControl, 0, 0)

Open in new window

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40454052
Oh dear
You have posted hundreds of questions on this forum, but don't seem to have absorbed any of the concepts of programming. I suggest that you start again with a beginners programming tutorial. Any should do
0
 

Author Comment

by:al4629740
ID: 40454080
I could do without the critical remarks...
0
 

Author Comment

by:al4629740
ID: 40454162
I took Grahams suggestion and figured it out.  Thanks for your help Eric.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 102
Updates not working for MS Windows 7 12 164
How to compare ms sql hashbytes results within vb6 5 73
Export Data to Different .csv Files 26 103
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

806 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