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:
If valid Then
'set internal class variable value AND return true
'just return false
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
Public Property Let HardDriveID(sVariable)
pHardDriveID = sVariable
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
> 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
>> 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"
> 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"
>> 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.