Property Let, Property Get 
Author Message
 Property Let, Property Get

Is there a way to use the Property Let statement in a class definition to
assign values in the following manner.

objMyClass.aProperty("collectionIdentifier") = aValue

Public Property Let aProperty(ByVal arg1, ByVal arg2)
    objMyCollection(arg1) = arg2
End Property   ?

can the value be retrieved using Property Get

aValue = objMyClass.aProperty("collectionIdentifier")

Public Property Get aProperty(ByVal arg1)
    aProperty = objMyCollection(arg1)
End Property   ??

the only other options I can think of is to expose objMyCollection as a
property itself, or make it a public member.

Also when are Microsoft going to implement inheritance and polymorphism into
VBScript classes? - Perhaps never, now that .NET is imminent.

thanks

root



Mon, 15 Dec 2003 20:00:00 GMT  
 Property Let, Property Get
hi Root,

I'm having a little trouble understanding your question.

You can't create collections in script, so your collection must be coming
from somewhere else.  (I assume it's either one of the collections built
into the language or instantiated via a createobject method).

If it's coming from somewhere else, you could just pass the collection back
from the class to your script, and then use normal "collection syntax",
i.e.,:

   Set myCollection = oMyClass.GetCollection()

   GetValue = myCollection("key") or, myCollection("key") = SetValue

cheers, jw


Quote:
> Is there a way to use the Property Let statement in a class definition to
> assign values in the following manner.

> objMyClass.aProperty("collectionIdentifier") = aValue

> Public Property Let aProperty(ByVal arg1, ByVal arg2)
>     objMyCollection(arg1) = arg2
> End Property   ?

> can the value be retrieved using Property Get

> aValue = objMyClass.aProperty("collectionIdentifier")

> Public Property Get aProperty(ByVal arg1)
>     aProperty = objMyCollection(arg1)
> End Property   ??

> the only other options I can think of is to expose objMyCollection as a
> property itself, or make it a public member.

> Also when are Microsoft going to implement inheritance and polymorphism
into
> VBScript classes? - Perhaps never, now that .NET is imminent.

> thanks

> root



Tue, 16 Dec 2003 04:03:08 GMT  
 Property Let, Property Get
Yes, you can create indexed properties for VBScript classes...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> Is there a way to use the Property Let statement in a class definition to
> assign values in the following manner.

> objMyClass.aProperty("collectionIdentifier") = aValue

> Public Property Let aProperty(ByVal arg1, ByVal arg2)
>     objMyCollection(arg1) = arg2
> End Property   ?

> can the value be retrieved using Property Get

> aValue = objMyClass.aProperty("collectionIdentifier")

> Public Property Get aProperty(ByVal arg1)
>     aProperty = objMyCollection(arg1)
> End Property   ??

> the only other options I can think of is to expose objMyCollection as a
> property itself, or make it a public member.

> Also when are Microsoft going to implement inheritance and polymorphism into
> VBScript classes? - Perhaps never, now that .NET is imminent.

> thanks

> root



Tue, 16 Dec 2003 07:14:53 GMT  
 Property Let, Property Get


Quote:
> hi Root,

> I'm having a little trouble understanding your question.

> You can't create collections in script,

yes you can, see below, it works a treat :)

<%
' ================================================
' ASP Collection item class definition
' ================================================

 Class ASPCollectionItem

'
============================================================================
=
' private member variables
'
============================================================================
=

  ' collection item key
  Private strKey

  ' collection item value
  Private strValue

'
============================================================================
=
' private methods
'
============================================================================
=

'
============================================================================
=
' public properties
'
============================================================================
=

 ' ===========
 ' === Key ===
 ' ===========
  Public Property Get Key()
   Key = strKey
  End Property

  Public Property Let Key(ByVal strKeyName)
   strKey = strKeyName
  End Property

 ' =============
 ' === Value ===
 ' =============
  Public Property Get Value()
   If IsObject(strValue) Then
    Set Value = strValue
   Else
    Value = strValue
   End If
  End Property

  Public Property Let Value(ByVal strValueData)
   strValue = strValueData
  End Property

  Public Property Set Value(ByVal objObject)
   Set strValue = objObject
  End Property

'
============================================================================
=
' public methods
'
============================================================================
=

 End Class

' ===============================================
' ASP Collection class definition
' ===============================================

 Class ASPCollection

'
============================================================================
=
' private member variables
'
============================================================================
=

  ' collection item array
  Public arrayItems

  ' collection item count
  Private lngCollectionCount

  ' last error
  Private strLastError

'
============================================================================
=
' private methods
'
============================================================================
=

 ' ===============
 ' === AddItem ===
 ' ===============
  Private Function AddItem(ByVal strKeyName, ByVal strValue)
   Dim lngCounter
   If lngCollectionCount > 0 Then
    lngCounter = 1
    Do While lngCounter <= lngCollectionCount
     If strKeyName = arrayItems(lngCounter).Key Then
      AddItem = False
      strLastError = "Failed to add key " & strKeyname & " : key name
already exists in this collection"
      Exit Function
     End If
     lngCounter = lngCounter + 1
    Loop
   End If

   lngCollectionCount = lngCollectionCount + 1
   ReDim Preserve arrayItems(lngCollectionCount)

   Set arrayItems(lngCollectionCount) = New ASPCollectionItem
   arrayItems(lngCollectionCount).Key = strKeyName
   If IsObject(strValue) Then
    Set arrayItems(lngCollectionCount).Value = strValue
   Else
    arrayItems(lngCollectionCount).Value = strValue
   End If

   AddItem = True
  End Function

'
============================================================================
=
' public properties
'
============================================================================
=

 ' =============
 ' === Count ===
 ' =============
  Public Property Get Count()
   Count = lngCollectionCount
  End Property

 ' =================
 ' === LastError ===
 ' =================
  Public Property Get LastError()
   LastError = strLastError
  End Property

'
============================================================================
=
' public methods
'
============================================================================
=

 ' ==================
 ' === Initialise ===
 ' ==================
  Public Function Initialise()
   ReDim arrayItems(1)
   lngCollectionCount = 0
   Initialise = True
   strLastError = ""
  End Function

 ' ===========
 ' === Add ===
 ' ===========
  Public Function Add(ByVal strKeyName, ByVal strValue)
   Add = AddItem(strKeyName, strValue)
  End Function

 ' =========================
 ' === [Default] GetItem ===
 ' =========================
  Public Default Function GetItem(ByVal strKeyName)
   Dim lngItemCounter
   lngItemCounter = 1
   Do While lngItemCounter <= lngCollectionCount
    If strKeyName = arrayItems(lngItemCounter).Key Then
     If IsObject(arrayItems(lngItemCounter).Value) Then
      Set GetItem = arrayItems(lngItemCounter).Value
     Else
      GetItem = arrayItems(lngItemCounter).Value
     End If

     Exit Function
    End If
    lngItemCounter = lngItemCounter + 1
   Loop
   GetItem = "Falied to get item " & strKeyName & " : key not found in
collection"
  End Function

 ' ===============
 ' === GetKeys ===
 ' ===============
  Public Function GetKeys()
   Dim lngCounter, arrayKeys
   If lngCollectionCount = 0 Then
    Redim arrayKeys(1)
    arrayKeys(1) = "_empty"
    GetKeys = arrayKeys
    Exit Function
   End If
   ReDim arrayKeys(lngCollectionCount)
   lngCounter = 1
   Do While lngCounter <= lngCollectionCount
    arrayKeys(lngCounter) = arrayItems(lngCounter).Key
    lngCounter = lngCounter + 1
   Loop
   GetKeys = arrayKeys
  End Function

 End Class

%>

 so your collection must be coming

Quote:
> from somewhere else.  (I assume it's either one of the collections built
> into the language or instantiated via a createobject method).

> If it's coming from somewhere else, you could just pass the collection
back
> from the class to your script, and then use normal "collection syntax",
> i.e.,:

>    Set myCollection = oMyClass.GetCollection()

>    GetValue = myCollection("key") or, myCollection("key") = SetValue

> cheers, jw



> > Is there a way to use the Property Let statement in a class definition
to
> > assign values in the following manner.

> > objMyClass.aProperty("collectionIdentifier") = aValue

> > Public Property Let aProperty(ByVal arg1, ByVal arg2)
> >     objMyCollection(arg1) = arg2
> > End Property   ?

> > can the value be retrieved using Property Get

> > aValue = objMyClass.aProperty("collectionIdentifier")

> > Public Property Get aProperty(ByVal arg1)
> >     aProperty = objMyCollection(arg1)
> > End Property   ??

> > the only other options I can think of is to expose objMyCollection as a
> > property itself, or make it a public member.

> > Also when are Microsoft going to implement inheritance and polymorphism
> into
> > VBScript classes? - Perhaps never, now that .NET is imminent.

> > thanks

> > root



Tue, 16 Dec 2003 14:29:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. property get / property let

2. Property Let vs. Property Set

3. vbs Class: Property Let Problem

4. property let/get

5. How to use Property Let

6. help: who can explain Property Get,Property Let,Property Set in control creation edtion for me?

7. help: who can explain Property Get,Property Let,Property Set in control creation edtion for me?

8. property let and get,

9. Property Get, Set Let with Classes

10. Error 451: let property not defined

11. Property Let Procedure Error

12. Property Let problem

 

 
Powered by phpBB® Forum Software