Results 1 to 9 of 9

Thread: Methods and properties

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80

    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

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Public Enum MyVals
    Val1 =1,
    Val2
    End Enum

    then as your arument for value2, pass in a variable of myVals type.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80
    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

  4. #4
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Why don't you use a boolean for value 2 - so then you would have either true or false.

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You may be thinking of the
    VB Code:
    1. [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:
    1. <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.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80
    Because ultimately i will have more than 2 items.....like 6


    Mag

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80
    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

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Oh, just use an Enum for the second parameter then.


    VB Code:
    1. Public Class1
    2.  
    3.  Public Enum myParameter
    4.    Franklin = 1
    5.    Widge= 2
    6.    Trance = 3
    7.  End Enum
    8.  
    9.  Public Function doThis(value1 as string, value2 as myParameter)
    10.  
    11.  End Function
    12.  
    13. End Class

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80
    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
  •  



Click Here to Expand Forum to Full Width