Help writing a method...

I've never written methods for a class. I'm trying to do something I think is simple and but I'm not sure how.

I want to input of an integer (public enum) and return text.

I am using this property:
        Property Argument() As WhereArgument
            Get
                Argument = pArgument
            End Get
            Set(ByVal value As WhereArgument)
                pArgument = value
            End Set
        End Property

    Public Enum WhereArgument
        equal = 0
        notequal = 1
        greater = 2
        less = 3
        greaterORequal = 4
        lessORequal = 5
    End Enum

I can do this but what I want to do is have some sort of custom method like a .tostring(of course named something else) but that returns " = "
Dim test As SQLWhere
            test.Argument = WhereArgument.equal
Dim Test2 as string = test.Argument.MyToString  'Test2 should be " = "

Please help me out by showing me how to write this method
LVL 1
LorneCashAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:

Public Function MyToString(wa As WhereArgument) As String
    If wa=WhereArgument.equal Then
       Return " = "
    ElseIf wa = WhereArgument.notequal Then
       Return " <> "
    ElseIf wa = WhereArgument.greater Then
       Return " > "
    ElseIf wa = WhereArgument.less Then
       Return " < "
    ElseIf wa = WhereArgument.greaterORequal Then
       Return " >= "
    ElseIf wa = WhereArgument.lessORequal Then
       Return " <= "
    End If
End Function
0
JuamezCommented:
You could use the select-case construct instead of an if-else construct, but the principle is exactly the same.
0
Jorge PaulinoIT Pro/DeveloperCommented:
Agree with Juamez, looks better this way:
    Public Function MyToString(ByVal arg As WhereArgument) As String
        Select Case arg
            Case WhereArgument.equal : Return "="
            Case WhereArgument.notequal : Return "<>"
            Case WhereArgument.greaterORequal : Return ">="
            Case WhereArgument.less : Return "<"
            Case WhereArgument.lessORequal : Return "<="
            Case WhereArgument.notequal : Return "<>"
            Case Else : Return String.Empty
        End Select
    End Function

Open in new window

0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Jorge PaulinoIT Pro/DeveloperCommented:
Another way, using Extension Methods:
' Create a module for the extension methods and define the WhereArgument only here
Imports System.Runtime.CompilerServices

Public Module myExtensions

    Public Enum WhereArgument
        equal = 0
        notequal = 1
        greater = 2
        less = 3
        greaterORequal = 4
        lessORequal = 5
    End Enum

    <Extension()> _
    Public Function MyToString(ByVal arg As WhereArgument) As String
        Select Case arg
            Case WhereArgument.equal : Return "="
            Case WhereArgument.notequal : Return "<>"
            Case WhereArgument.greaterORequal : Return ">="
            Case WhereArgument.less : Return "<"
            Case WhereArgument.lessORequal : Return "<="
            Case WhereArgument.notequal : Return "<>"
            Case Else : Return String.Empty
        End Select
    End Function

End Module


' Change in the SQLWhere class the property declaration to ... As myExtensions.WhereArgument
Public Class SQLWhere

    Private pArgument As WhereArgument
    Property Argument() As myExtensions.WhereArgument
        Get
            Argument = pArgument
        End Get
        Set(ByVal value As WhereArgument)
            pArgument = value
        End Set
    End Property

End Class


' Finally
        Dim test As New SQLWhere
        test.Argument = WhereArgument.equal
        Dim result As String = test.Argument.MyToString()

Open in new window

0
Jorge PaulinoIT Pro/DeveloperCommented:
Small change (but it still works that way) ... you can remove the myExtensions call
Change:
Property Argument() As myExtensions.WhereArgument
To:
Property Argument() As WhereArgument
0
LorneCashAuthor Commented:
OK here's what I did that works... it was almost what @jpaulino said:
the only major difference was that the Enum WhereArgument had to be in teh SQLWhere Class or it would give an error message like this:
... Cannot expose the type '...WhereArgument' outside the project through class ...

Imports System.Runtime.CompilerServices

Namespace SQLBackend
     Public Class SQLWhere
        Private pArgument As WhereArgument
        Public Enum WhereArgument
            equal = 0
            notequal = 1
            greater = 2
            less = 3
            greaterORequal = 4
            lessORequal = 5
        End Enum
        Property Argument() As WhereArgument
            Get
                Argument = pArgument
            End Get
            Set(ByVal value As WhereArgument)
                pArgument = value
            End Set
        End Property
    End Class
End Namespace

Module SQLMethods

    <Extension()> _
    Public Function MyToString(ByVal arg As SQLBackend.SQLWhere.WhereArgument) As String
        Select Case arg
            Case SQLBackend.SQLWhere.WhereArgument.equal : Return "="
            Case SQLBackend.SQLWhere.WhereArgument.notequal : Return "<>"
            Case SQLBackend.SQLWhere.WhereArgument.greaterORequal : Return ">="
            Case SQLBackend.SQLWhere.WhereArgument.less : Return "<"
            Case SQLBackend.SQLWhere.WhereArgument.lessORequal : Return "<="
            Case SQLBackend.SQLWhere.WhereArgument.notequal : Return "<>"
            Case Else : Return String.Empty
        End Select
    End Function

End Module

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
>... Cannot expose the type '...WhereArgument' outside the project through class ...
Its because the enum is declared as Private. If you make it friend or public, it would be fine in its current location.
0
LorneCashAuthor Commented:
actually it was declared as public... didn't try friend... that may have worked
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.