![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. Quote: > 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 Quote: > my property return a bool value? the purpose being to move input Quote: > 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 Quote: > 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 Specs![]() |
| | #3 (permalink) |
| | 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 Quote: > 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? 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. Quote: > 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? 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... Quote: > 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? /Al |
My System Specs![]() |
| | #4 (permalink) |
| | 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 Quote: > 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 Quote: >> 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. > Quote: >> 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... > Quote: >> 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Routine Maintenance Advice Wanted | General Discussion | |||
| Calling a JavaScript Sub-Routine | VB Script | |||
| Set Focus To Specific Property In Property Grid | .NET General | |||
| re: 'Save As' routine | VB Script | |||