Windows Vista Forums

can a property let routine return a value?
  1. #1


    James Guest

    can a property let routine return a value?

    using vbscript and wsh...

    I often makes classes

    class test

    function this

    end function

    function that

    end function

    property let myprop

    end property

    property get myprop

    end property

    end class



    My properties are usually very simple and the input validation is done in
    the main routine, not within the property itself. My question is: can I make
    my property return a bool value? the purpose being to move input validation
    into the property function. I know I could just change the property to a
    function to achieve this but I was wondering if it could be done as a
    property?

    eg. end result would be to be able to use something like this in main script
    section:

    While Not myClass.myProperty = InputBox "myprompt"
    'nothing
    Loop

    basically setting the property value to user input value but inside the
    property let code also returning either true or false on the sucess of
    setting the property, which would control the loop... keep looping until a
    valid value is input.

    possible or just use a function?



      My System SpecsSystem Spec

  2. #2


    mayayana Guest

    Re: can a property let routine return a value?

    Someone else may understand your question better
    than I do. Your idea seems very confusing to me.
    I'd be inclined to cleanly separate processes, for
    simplicity and clarity of code.

    But it is possible to
    use multiple parameters in a property. The following is
    an example of a simple array property, where the property
    B allows boolean values to be stored at indexes.
    -------------
    Dim A2
    Set A2 = New A

    A2.B(2) = True
    MsgBox A2.B(2)

    Set A2 = Nothing


    Class A
    Dim par1, par2(10)

    Property Let B(Index, Bool1)
    par1 = sval
    par2(Index) = Bool1
    End Property

    Property Get B(Index)
    B = par2(Index)
    End Property
    End Class
    ----------------

    The same thing could be used as a dictionary or collection.
    For instance, you could have 2 arrays in the class,
    each storing strings. By using both you could then
    create a custom dictionary class. Basically you can
    do whatever you want inside the class. It's just a matter
    of what interface design is going to be most intuitive
    and usable.

    > using vbscript and wsh...
    >
    > I often makes classes
    >
    > class test
    >
    > function this
    >
    > end function
    >
    > function that
    >
    > end function
    >
    > property let myprop
    >
    > end property
    >
    > property get myprop
    >
    > end property
    >
    > end class
    >
    > My properties are usually very simple and the input validation is done in
    > the main routine, not within the property itself. My question is: can I
    make

    > my property return a bool value? the purpose being to move input
    validation

    > into the property function. I know I could just change the property to a
    > function to achieve this but I was wondering if it could be done as a
    > property?
    >
    > eg. end result would be to be able to use something like this in main
    script

    > section:
    >
    > While Not myClass.myProperty = InputBox "myprompt"
    > 'nothing
    > Loop
    >
    > basically setting the property value to user input value but inside the
    > property let code also returning either true or false on the sucess of
    > setting the property, which would control the loop... keep looping until a
    > valid value is input.
    >
    > possible or just use a function?
    >
    >


      My System SpecsSystem Spec

  3. #3


    Al Dunbar Guest

    Re: can a property let routine return a value?

    Add me to the list of people somewhat confused as to what it is you want to
    be able to do, but here are some comments....

    "James" <noone@xxxxxx> wrote in message
    news:%23FKK%23%23tKJHA.5532@xxxxxx

    > using vbscript and wsh...
    >
    > I often makes classes
    >
    > class test
    >
    > function this
    >
    > end function
    >
    > function that
    >
    > end function
    >
    > property let myprop
    >
    > end property
    >
    > property get myprop
    >
    > end property
    >
    > end class
    >
    > My properties are usually very simple and the input validation is done in
    > the main routine, not within the property itself. My question is: can I
    > make my property return a bool value?
    Yes. By assigning boolean values to them, i.e.

    object.myprop = true
    if object.myprop then
    msgbox "it is true"
    else
    msgbox "it is false"
    end if

    But it sounds more as if you are wanting, as a side effect, the property
    code to return some status value associated with the action carried out. If
    that is the case, what meaning is this value supposed to have? It could, for
    example, be that you want it to return the success of the attempt, i.e.:

    if ( not (object.myprop = "invalid data") ) then
    msgbox "failed to assign invalid information to property"
    end if

    First, there is no such side effect possible. Second, if there was or if you
    found a way to overload the functionality of the built-in features of the
    class object, I think it would be confusing and ambiguous.

    > the purpose being to move input validation into the property function.
    > I know I could just change the property to a function to achieve this but
    > I was wondering if it could be done as a property?
    Ah, I think I get it now...

    The validation code in your properties could set a code to be retrieved from
    another property by the calling program...


    object.myprop = inputbox("enter data")
    if object.validationError then...

    > eg. end result would be to be able to use something like this in main
    > script section:
    >
    > While Not myClass.myProperty = InputBox "myprompt"
    > 'nothing
    > Loop
    >
    > basically setting the property value to user input value but inside the
    > property let code also returning either true or false on the sucess of
    > setting the property, which would control the loop... keep looping until a
    > valid value is input.
    >
    > possible or just use a function?
    I dunno. I'd stick to keeping things simple.

    /Al



      My System SpecsSystem Spec

  4. #4


    James Guest

    Re: can a property let routine return a value?

    I likely didn't explain well but Al, I think you got what I was getting at.
    Basically, just like when doing batch files which call external commands
    those commands have a return value which you check for error condition. I
    was wondering about adding that functionality to my class properties so that
    anytime I set a property from my main code there would be a return value
    indicating whether the property value was set or not (whether or not it made
    it through some input validation checking). Its more an acedemic question to
    me with regard to understanding the language structures... many ways to
    accomplish the same thing.

    I do this sometimes now using a function structured like this:
    Function SetHardDriveID(sVariable)
    'validate input
    If valid Then
    'set internal class variable value AND return true
    Else
    'just return false
    End If
    End Function

    Then I could loop on the function call until the user input is good, for
    example. So I was wondering if/how the same thing could be done using
    property instead of function. Example of a property of mine follows:

    Public Property Get HardDriveID
    HardDriveID = pHardDriveID
    End Property

    Public Property Let HardDriveID(sVariable)
    pHardDriveID = sVariable
    End Property

    Al, your suggestion of setting another property such as
    object.ValidationError is another way this could be done. What it really
    comes down to is 'where' the input validation is occurring... I was thinking
    about this... I'm creating some general purpose classes, so I want as much
    functionality already in the class so that when I use the class elseware its
    as easy and short as possible. Input validation often takes several lines of
    code so instead of having to do that in the main calling program everytime I
    was wondering about ways to encapsulate it in the class, with the effect
    being fewer, simpler, lines of code in calling program... and the
    object.ValidationError idea is a good one. Thanks.

    sorry for the unclear post... hopefully that cleared it up a little.




    "Al Dunbar" <AlanDrub@xxxxxx> wrote in message
    news:e%23Nr4mzKJHA.1556@xxxxxx

    > Add me to the list of people somewhat confused as to what it is you want
    > to be able to do, but here are some comments....
    >
    > "James" <noone@xxxxxx> wrote in message
    > news:%23FKK%23%23tKJHA.5532@xxxxxx

    >> using vbscript and wsh...
    >>
    >> I often makes classes
    >>
    >> class test
    >>
    >> function this
    >>
    >> end function
    >>
    >> function that
    >>
    >> end function
    >>
    >> property let myprop
    >>
    >> end property
    >>
    >> property get myprop
    >>
    >> end property
    >>
    >> end class
    >>
    >> My properties are usually very simple and the input validation is done in
    >> the main routine, not within the property itself. My question is: can I
    >> make my property return a bool value?
    >
    > Yes. By assigning boolean values to them, i.e.
    >
    > object.myprop = true
    > if object.myprop then
    > msgbox "it is true"
    > else
    > msgbox "it is false"
    > end if
    >
    > But it sounds more as if you are wanting, as a side effect, the property
    > code to return some status value associated with the action carried out.
    > If that is the case, what meaning is this value supposed to have? It
    > could, for example, be that you want it to return the success of the
    > attempt, i.e.:
    >
    > if ( not (object.myprop = "invalid data") ) then
    > msgbox "failed to assign invalid information to property"
    > end if
    >
    > First, there is no such side effect possible. Second, if there was or if
    > you found a way to overload the functionality of the built-in features of
    > the class object, I think it would be confusing and ambiguous.
    >

    >> the purpose being to move input validation into the property function.
    >> I know I could just change the property to a function to achieve this but
    >> I was wondering if it could be done as a property?
    >
    > Ah, I think I get it now...
    >
    > The validation code in your properties could set a code to be retrieved
    > from another property by the calling program...
    >
    >
    > object.myprop = inputbox("enter data")
    > if object.validationError then...
    >

    >> eg. end result would be to be able to use something like this in main
    >> script section:
    >>
    >> While Not myClass.myProperty = InputBox "myprompt"
    >> 'nothing
    >> Loop
    >>
    >> basically setting the property value to user input value but inside the
    >> property let code also returning either true or false on the sucess of
    >> setting the property, which would control the loop... keep looping until
    >> a valid value is input.
    >>
    >> possible or just use a function?
    >
    > I dunno. I'd stick to keeping things simple.
    >
    > /Al
    >
    >


      My System SpecsSystem Spec

can a property let routine return a value? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert simple ADODB routine from VBA to VB.net UsenetUser .NET General 2 18 Jun 2009
Calling a JavaScript Sub-Routine Leona Leal Educator VB Script 3 21 Jan 2009
Set Focus To Specific Property In Property Grid Derek Hart .NET General 10 06 Oct 2008
re: 'Save As' routine Bishop VB Script 0 18 Jul 2008
Use my custom TypeDescriptor to obtains default Value on property inXAML Property Editor of Visual Studio 2008 azerty Avalon 0 14 Apr 2008