Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

class bave a blank property

Posted on 2006-07-21
1
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
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…

721 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