Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Mar 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not supportet arguments to functions? (1)

    As far as I can understand I'm only allowed to transfere these types as arguments to functions:

    Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (not currently supported), Date, String, or (except fixed length), Object, Variant, or any user-defined type.

    (quote from MS VB help 2003)

    What do I do then if I have a control (like a combo or at button or some other) that I want to do something with in a function??? This restriction is rather silly *SS* - in c/c++ this is no problem what so ever:

    void foo(CComboBox *pMyCtrl) {...} ' Where * = ByRef

    Can I do the same in VB/VBA?

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Not supportet arguments to functions? (1)

    In Excel VBA, one can use any Object:

    <pre>Sub test()
    If SetCaption(UserForm1.CommandButton1) Then
    UserForm1.Show
    End If
    End Sub

    Public Function SetCaption(oCtl As MSForms.CommandButton) As Boolean
    oCtl.Caption = "foo"
    SetCaption = True
    End Function</pre>

    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Not supportet arguments to functions? (1)

    The text you quote from the online help applies to the return value of a function, not to its arguments. Anyway, it's not important since controls are objects. It is perfectly well possible to do something like this in VBA:

    Function MyFunction(cbo As MSForms.ComboBox) As String

    This will not work for a function meant to be used as a custom worksheet function, since there is no way to pass a control as an argument in a worksheet function.

  4. #4
    Lounger
    Join Date
    Mar 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Not supportet arguments to functions? (1)

    OK - thanx' folks! I misunderstood and I was working on a invisible ctrl. and it did'nt like that *S*

    It works now!

  5. #5
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Not supportet arguments to functions? (1)

    You should be able to work on an invisible control. Just make sure you don't try to select it. You can not select a hidden object, but you can work with it...

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •