Results 1 to 11 of 11

Thread: How could I accomplish creating a property that can only set and return certian info?

  1. #1

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Question How could I accomplish creating a property that can only set and return certian info?

    I am working on a program that searches Active Directory. I have a feature working right now where when the user searches for something a object is created from a class I desgined. This object will contain various information about what to search for in active directory.

    I want to create a property in this class that will return and set only certian strings. I know I could use a select case on the value to make sure it's correct however using this method when I go to set the property I will be going back and forth in my code to make sure the strings are exactlly the same so no errors are produced. I want intellisence to automaticly display valid values which can be set.

    I was thinking about using an enumeration however an enuermation can only contain numbers and no strings. So I created a function that will accept the enuermation and returns a string based one what is selected in the enumeration. This just dosen't work well inside my class.

    What do you guys suggest I try doing.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: How could I accomplish creating a property that can only set and return certian i

    well as I was reading this it sounded like you were going down the correct path. What exactly doesnt work well inside your class when you use the enum in/string out property?

  3. #3
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Re: How could I accomplish creating a property that can only set and return certian i

    Wrote something similar recently. Created a ADSearcher class that returned an ADResult object. AD properties loaded into the ADResult object were either explicity set via an enumeration or via a boolean ReturnAll property.

    Anyway, while an enum is technically an int behind the scenes, you can just as easily evaluate it as a string and even interate through it as a set of string objects.

  4. #4

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Re: How could I accomplish creating a property that can only set and return certian info?

    The problem I am having is a property can only set and return one type of data. What I want to do is have the ability to set the property using an enumeration and when I assign something to a variable from the property I want it to return a string.

    I can't figure this out with out having to use two properties, and a function. Here is the code I have so far. enumSaveName is an enumeration for the names that are valid and ConvertSaveNameEnum returns a string based on what value the enuermation holds.

    VB Code:
    1. Public Property enumConvert(ByVal enumName As enumSaveName) As enumSaveName
    2.         Get
    3.             Return ConvertSaveNameEnum(enumName)
    4.         End Get
    5.         Set(ByVal Value As enumSaveName)
    6.             enumSaveName = Value
    7.         End Set
    8.     End Property

  5. #5
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: How could I accomplish creating a property that can only set and return certian info?

    I think you should just create two Public Functions: GetThingy and SetThingy.
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

  6. #6
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Re: How could I accomplish creating a property that can only set and return certian i

    OK. Let's step back a bit.

    Are you trying to set properties of an object, call a function (that searches AD), and then possibly reset those same properties based on the results of your search?

    I understand your input requirement (an enum so you don't have to parse through the input value for a valid format), but I'm somehow missing your output requirement.

    Might be having a dense morning.

  7. #7

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Re: How could I accomplish creating a property that can only set and return certian i

    Quote Originally Posted by Briantcva
    OK. Let's step back a bit.

    Are you trying to set properties of an object, call a function (that searches AD), and then possibly reset those same properties based on the results of your search?

    I understand your input requirement (an enum so you don't have to parse through the input value for a valid format), but I'm somehow missing your output requirement.

    Might be having a dense morning.
    I have a module that has many various searching functions in them. All the functions accept an object of this type. This object mearly contains information on how the search should be performed and what to look for. This specific property will be used in a function that adds information to a list box based on what the user is searching for. The listbox will contain all the pervious searches that have been performed. This property will be used to tell the function what to prefix the items added to the listbox based on what they searched for.

    ex:

    VB Code:
    1. 'LookinFor is an object created from this class
    2. lstsaved.items.add(lookingfor.SavedSearchName & " : " & txtSearch.text)

    something to that effect.

  8. #8
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: How could I accomplish creating a property that can only set and return certian info?

    Enumerations can be directly converted to their defined names at runtime you know.

    VB Code:
    1. Enum fish as integer
    2. Haddock=0
    3. Pilchard=1
    4. Herring=2
    5. end enum
    6.  
    7. '...
    8.  
    9. dim billy as fish = fish.Herring
    10. messagebox.show(billy.tostring) 'displays "Herring"

    Just a thought.
    I don't live here any more.

  9. #9

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Re: How could I accomplish creating a property that can only set and return certian info?

    Quote Originally Posted by wossname
    Enumerations can be directly converted to their defined names at runtime you know.

    VB Code:
    1. Enum fish as integer
    2. Haddock=0
    3. Pilchard=1
    4. Herring=2
    5. end enum
    6.  
    7. '...
    8.  
    9. dim billy as fish = fish.Herring
    10. messagebox.show(billy.tostring) 'displays "Herring"

    Just a thought.
    I never knew that, that's some good information, only problem is i would have to use some extra code this way just to get a string into the listbox. It would be so much easier to just be able to use lookingfor.SaveName

  10. #10
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: How could I accomplish creating a property that can only set and return certian info?

    Sure, just passing on a nugget of knowledge
    I don't live here any more.

  11. #11

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Re: How could I accomplish creating a property that can only set and return certian info?

    Just a throught do you think it would be possible to use the tostring method on the propety since it returns an enum?

    lookingfor.SaveName.ToString ??


    Ehhh nevermind this woudln't work in my exsact case becuase sometimes the strings I want to return actually have a space in them and you can have a space in an enumerations value

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