Solved

class bave a blank property

Posted on 2006-07-21
1
177 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 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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