Results 1 to 6 of 6

Thread: Function Arguments

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    23

    Function Arguments

    Is there a way to detect what type of argument is being sent? I have four different user defined types and some of my functions work with all four. Instead of defining the function so it has to be called with a ton of commas (runfunction , , , data4) I would it to determine what the argument is on its own (runfunction data4).

    I figure maybe a variant would work, but if that is the answer, how would I check to see which user defined type the variant holds?

    Thanks.

  2. #2
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    try the TypeName function

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Could try the VarType function
    VB Code:
    1. Dim something As Variant
    2.  
    3. something = "Hello"
    4.  
    5. MsgBox VarType(something)

  4. #4
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Add the following ENUM and for each of your User Defined Types, add what's in italics:
    VB Code:
    1. 'Add the following
    2. Private Enum iUDTType
    3.     UDT_One = 1
    4.     UDT_Two = 2
    5.     UDT_Three = 3
    6.     UDT_Four = 4
    7. End Enum
    8.  
    9. Private Type MyUDT
    10.     [i]UDTType As iUDTType[/i]
    11. End Type

    When you need to check which one is which, all you have to do is check the UDTType property.

    VB Code:
    1. Public Function MyFunction(mUDT As Object)
    2.     Select Case mUDT.UDTType
    3.         Case UDT_One
    4.             MsgBox "Woo One!"
    5.         Case UDT_Two
    6.             MsgBox "WooHoo Two!!"
    7.         Case UDT_Three
    8.             MsgBox "WooHooHee Three!!!"
    9.         Case UDT_Four
    10.             MsgBox "WooHooHeeHoo Four!!!!"
    11.     End Select
    12. End Function
    Hope this gives you and idea
    -Excalibur

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Actually what you are asking is differnt thatn what answers you got.

    He wants this:


    say he has a function

    function Blah (par1, par2, par3) as blah

    if he just wants to use the 3rd parameter all he wants to type is

    Blah par3

    and have the functino determine which parameter it is

    You cannot do this!

    basically he doesnt want to type a couple commas

    blah ,,par3

    that is how i understood it.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Ok, if that's the case:
    VB Code:
    1. Function Blah(Optional Blah1, Optional Blah2, Optional Blah3) As varBlah
    2.     MsgBox "wee"
    3. End Sub
    4.  
    5. Private Sub Form_Load()
    6.     MsgBox Blah Blah3:=Blah4
    7. End Sub
    -Excalibur

Posting Permissions

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



Click Here to Expand Forum to Full Width