|
-
Apr 21st, 2004, 12:53 PM
#1
Thread Starter
Lively Member
Methods and properties
I am trying to figure out how to make a function so that you can only pick certain arguments for the argument list. Not Overidding the function.
For Example:
Sub New (ByVal value As String, ByVal value2 As String)
I want the value 2 to only have the value 1 or 2.....
Can't i set that up in the argument list? Iv'e looked everywhere and i thought i remember seeing something about it.
Mag
-
Apr 21st, 2004, 01:46 PM
#2
Frenzied Member
Public Enum MyVals
Val1 =1,
Val2
End Enum
then as your arument for value2, pass in a variable of myVals type.
-
Apr 21st, 2004, 02:07 PM
#3
Thread Starter
Lively Member
Not that.....Something like......
Sub New (ByVal value As String, ByValue value2 As String = 1, 2)
So on the call they can only send in those two values.
Example TheCall("weeee", "1") or TheCall("something", "2")
Nothing else can be sent in to the value2 parameter except for 1 and 2.
Mag
-
Apr 21st, 2004, 02:26 PM
#4
Fanatic Member
Why don't you use a boolean for value 2 - so then you would have either true or false.
-
Apr 21st, 2004, 02:40 PM
#5
I wonder how many charact
You may be thinking of the
VB Code:
[b]<AttributeTarget>[/b]Public Function myTest(value1 as string, value2 as string)
I think its AttributeTarget, then again, there's a whole boatload of these < ...> operators that you can apply to methods, properties and classes... sorry i can't be for certain or more specific.
I think this link describes them (further on down when they describe how to validate a property with their own attribute class called validLength
VB Code:
<ValidLength>Public Property Width As Integer
:
http://www.vbdotnetheaven.com/Code/Jun2003/2033.asp
Last edited by nemaroller; Apr 21st, 2004 at 02:45 PM.
-
Apr 21st, 2004, 02:45 PM
#6
Thread Starter
Lively Member
Because ultimately i will have more than 2 items.....like 6
Mag
-
Apr 21st, 2004, 02:50 PM
#7
Thread Starter
Lively Member
Well for example the messagebox function will only allow you to sellect certain types of graphics like the exclamation point and the red x in its call.
Mag
-
Apr 21st, 2004, 02:53 PM
#8
I wonder how many charact
Oh, just use an Enum for the second parameter then.
VB Code:
Public Class1
Public Enum myParameter
Franklin = 1
Widge= 2
Trance = 3
End Enum
Public Function doThis(value1 as string, value2 as myParameter)
End Function
End Class
-
Apr 21st, 2004, 03:55 PM
#9
Thread Starter
Lively Member
Thanks For the replies......
Im stupid. Koven tried to tell me....
Mag
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
|