Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

class bave a blank property

Posted on 2006-07-21
1
Medium Priority
?
182 Views
Last Modified: 2010-04-23
I have a class called status which is pretty much just a status boolean, and a message.

So I can return, false, and "Failed for this reason"

Is there a way to return a value when you reference the object, without a property?


        Dim saveTestResults As Status
        MsgBox(saveTestResults.status) 'would pop up true or false

        MsgBox(saveTestResults) 'I would like this to also return true or false
        if (saveTestResults) then 'this is what I really want to do
        end if

Public Class Status

    Private myStatus As Boolean = False
    Private myMessage As String = ""

    Public Property status() As Boolean
        Get
            status = myStatus
        End Get
        Set(ByVal value As Boolean)
            myStatus = value
        End Set
    End Property

    Public Property message() As String
        Get
            message = myMessage
        End Get
        Set(ByVal value As String)
            myMessage = value
        End Set
    End Property

    Public Sub setStatus(ByVal message$, ByVal status As Boolean)

        myStatus = status
        myMessage = message

    End Sub

End Class
0
Comment
Question by:jackjohnson44
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 17155065
This is possibly a little crude, but you could achieve the effect you want by overriding the = and <> operators (in v2.0 at least):

Public Class Status

    Private myStatus As Boolean = False
    Private myMessage As String = ""

    Public Property status() As Boolean
        Get
            status = myStatus
        End Get
        Set(ByVal value As Boolean)
            myStatus = value
        End Set
    End Property

    Public Property message() As String
        Get
            message = myMessage
        End Get
        Set(ByVal value As String)
            myMessage = value
        End Set
    End Property

    Public Sub setStatus(ByVal message$, ByVal status As Boolean)

        myStatus = status
        myMessage = message

    End Sub

    Public Shared Operator =(ByVal lhs As Status, ByVal rhs As Object) As Boolean
        Return lhs.status
    End Operator

    Public Shared Operator <>(ByVal lhs As Status, ByVal rhs As Object) As Boolean
        Return Not lhs.status
    End Operator

End Class

Then use it like:

        Dim o As New Status
        o.status = True

        If o = True Then
            MessageBox.Show("Its True")
        End If

You still need to explicitly check True or False, because you can't just make a property Default unless it has an index otherwise you cause an ambiguity with the assignment operator.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question