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.
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?
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.
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:
Public Property enumConvert(ByVal enumName As enumSaveName) As enumSaveName
Get
Return ConvertSaveNameEnum(enumName)
End Get
Set(ByVal Value As enumSaveName)
enumSaveName = Value
End Set
End Property
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.
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.
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:
'LookinFor is an object created from this class
lstsaved.items.add(lookingfor.SavedSearchName & " : " & txtSearch.text)
something to that effect.
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:
Enum fish as integer
Haddock=0
Pilchard=1
Herring=2
end enum
'...
dim billy as fish = fish.Herring
messagebox.show(billy.tostring) 'displays "Herring"
Just a thought.
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:
Enum fish as integer
Haddock=0
Pilchard=1
Herring=2
end enum
'...
dim billy as fish = fish.Herring
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
Re: How could I accomplish creating a property that can only set and return certian info?
Sure, just passing on a nugget of knowledge :)
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 :(