Solved

how to execute this code - Argument not optional

Posted on 2014-11-19
4
137 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 69

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now