Solved

Passing a optional argument

Posted on 2007-11-30
3
146 Views
Last Modified: 2013-12-26
Hi experts
I have 5 mshflexgrids on a form 3 are contained in pictureboxs I am trying adjust the grids widths, based on the column widths and am trying to also set the picture widths as optional argument. The code below works fine if i pass the picture argument, but fails if with don't with a "Object variable not set" error message. How can i correct this?

Sub AdjustGridWidth(grd As MSHFlexGrid, Optional pic As PictureBox)
    Dim i As Integer
    Dim iWidth As Integer
   
 With grd
    For i = 1 To .Cols - 1
    iWidth = iWidth + .ColWidth(i) + 13
    .Width = iWidth
   Next i
 End With
   
  If IsMissing(pic) Then
    Exit Sub
   End If
   
    With pic
    pic.Width = iWidth
    End With
 
   
    End Sub
0
Comment
Question by:isnoend2001
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 total points
ID: 20384022
Replace:

  If IsMissing(pic) Then
    Exit Sub
   End If

with:

  If pic Is Nothing Then
    Exit Sub
   End If

IsMissing only works whne the argument is defined as Variant.
0
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 125 total points
ID: 20384068
Try this instead.  IsMissing only works with variants.  (See the help.)
Sub AdjustGridWidth(grd As MSHFlexGrid, Optional pic As PictureBox = Nothing)

    Dim i As Integer

    Dim iWidth As Integer

    

    With grd

        For i = 1 To .Cols - 1

            iWidth = iWidth + .ColWidth(i) + 13

            .Width = iWidth

        Next i

    End With

    

    If Not pic Is Nothing Then

        With pic

            pic.Width = iWidth

        End With

    End If

End Sub

Open in new window

0
 

Author Closing Comment

by:isnoend2001
ID: 31411983
Thanks both work perfect
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 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

24 Experts available now in Live!

Get 1:1 Help Now