|
-
Sep 14th, 2001, 10:52 AM
#1
Thread Starter
Junior Member
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.
-
Sep 14th, 2001, 10:57 AM
#2
Frenzied Member
try the TypeName function
-
Sep 14th, 2001, 10:58 AM
#3
PowerPoster
Could try the VarType function
VB Code:
Dim something As Variant
something = "Hello"
MsgBox VarType(something)
-
Sep 14th, 2001, 11:15 AM
#4
Fanatic Member
Add the following ENUM and for each of your User Defined Types, add what's in italics:
VB Code:
'Add the following
Private Enum iUDTType
UDT_One = 1
UDT_Two = 2
UDT_Three = 3
UDT_Four = 4
End Enum
Private Type MyUDT
[i]UDTType As iUDTType[/i]
End Type
When you need to check which one is which, all you have to do is check the UDTType property.
VB Code:
Public Function MyFunction(mUDT As Object)
Select Case mUDT.UDTType
Case UDT_One
MsgBox "Woo One!"
Case UDT_Two
MsgBox "WooHoo Two!!"
Case UDT_Three
MsgBox "WooHooHee Three!!!"
Case UDT_Four
MsgBox "WooHooHeeHoo Four!!!!"
End Select
End Function
Hope this gives you and idea
-
Sep 14th, 2001, 11:57 AM
#5
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.
-
Sep 14th, 2001, 01:58 PM
#6
Fanatic Member
Ok, if that's the case:
VB Code:
Function Blah(Optional Blah1, Optional Blah2, Optional Blah3) As varBlah
MsgBox "wee"
End Sub
Private Sub Form_Load()
MsgBox Blah Blah3:=Blah4
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|