Thanks for the reply, and I appreciate the input.

However, I think I should apologize for not making my first post as
clear as it should have been. When all is said and done, I would like
to be able to code this:
"
enum states
    x
    o
    othervalue1
    othervalue2
end enum

public sub main()
    dim enumVariable as states = x
    dim str as String = enumVariable
    msgbox(str)
end sub
"
and then call the main subroutine and have a message box pop up that
instead of saying the integer value of states.x (in this case "0"),
says "Value X" (or whatever).

I understand that i could do this:
"
public class statesConverted
    public enum states
        value1
        value2
        value3
        value4
    end enum

    public value as states

    public sub New()
        value = states.value1
    end sub

    public shared widening operator CType(variable as statesConverted)
as String
        select case variable.value
            case states.value1
                return "This is value 1"
            case else
                return "Other values"
        end select
    end operator
end class

public sub main()
    dim newVariable as new statesConverted()
    msgbox(newVariable) 'will work
    msgbox(newVariable.value) 'still won't do what i want
end sub
"
and accomplish basically the same idea, but I run into the same
problems as before whenever I try to turn the enumerated type into a
string.

So now my revised question: does vb.net have the capability to
overload operators for enumerated types without using a container
class to act as a sort of middle man?

Thanks again.

On Nov 28, 12:51 am, Cerebrus <[EMAIL PROTECTED]> wrote:
> I don't understand why this would be a problem. You would simply
> declare both the operator overloads in the class that contains the
> "States" enum.
>
> On Nov 27, 10:01 am, thomat65 <[EMAIL PROTECTED]> wrote:
>
> > Hey everyone!
>
> > I've run into a slight snag with VB.NET where I need a variable of an
> > enumerated type such as:
>
> > "
> >     Public Enum States
> >         x = 0
> >         o
> >         unmarked
> >         unknown
> >     End Enum
> > "
>
> > to be converted into some arbitrary string value other than "x", "o",
> > "unmarked", or "unknown", and vise versa possibly with an overloaded
> > operator like:
>
> > "
> >     Public Shared Widening Operator CType(ByVal State As States) As
> > String
> >         'useful stuff here...
> >     End Operator
> > "
>
> > but I can't just put this overloaded CType function in the enum block
> > for obvious reasons, so where would it go? Am I missing something or
> > is it simply impossible to overload operators for enumerated types in
> > VB?
>
> > To give you a further understanding of what I want, in C++ overloading
> > operators for situations like this was quite simple and
> > straightforward. All you would have to do is say something like
>
> > "
> >     States operator[operator here](some parameters)
> >         {/*code here*/}
> > "
>
> > and it would do exactly what I needed with no fuss.

Reply via email to