Classes and Arrays
- From: "Damon Birrell" <sopdamon.nospam@xxxxxxxxxxx>
- Date: Wed, 15 Jun 2005 13:28:12 +1000
Hi all
I am stuck with a problem relating to dynamic arrays and classes. I am
writing some code to audit folders on a network share and perform some
changes based on the groups, domains and permissions. In order to do this, I
have created a class called "record" to store information about a folder and
its permissions:
Record
Folder
Perms
The Perms property is a dynamic array as per
http://www.4guysfromrolla.com/webtech/032800-1.shtml
Each element in the Perms array should be another class called PermRec.
These records hold each group and the associated permissions for that
folder.
PermRec
Array of elements containing:
Group
Domain
Perm
I have some example code below that I cannot get to work. Can somebody
please help to explain why I get an error when attempting to assign a class
to the array. i.e. R.Perms.Data(0) = P
Any help would be greatly (and urgently) appreciated!
Regards,
Damon
' ###########CODE STARTS HERE ###############
Class PermRec
Public Group
Public Domain
Public Perm
'********* EVENT HANDLERS ************
Private Sub Class_Initialize()
Group = ""
Perm = ""
Domain = ""
End Sub
Private Sub Class_Terminate()
End Sub
End Class
'-----------------------------------------------------------------------
Class DynamicArray
'************** Properties **************
Private aData
'*********** Event Handlers *************
Private Sub Class_Initialize()
Redim aData(0)
Set aData(0) = New PermRec
End Sub
'************ Property Get **************
Public Property Get Data(iPos)
'Make sure the end developer is not requesting an
'"out of bounds" array element
If iPos < LBound(aData) or iPos > UBound(aData) then
Exit Property 'Invalid range
End If
Data = aData(iPos)
End Property
Public Property Get DataArray()
DataArray = aData
End Property
'************ Property Let **************
Public Property Let Data(iPos, varValue)
'Make sure iPos >= LBound(aData)
If iPos < LBound(aData) Then
Exit Property
End If
If iPos > UBound(aData) then
'We need to resize the array
Redim Preserve aData(iPos)
Set aData(iPos) = New PermRec
aData(iPos) = varValue
Else
'We don't need to resize the array
' Error occurs at this next line
aData(iPos) = varValue
End If
End Property
'************** Methods *****************
Public Function StartIndex()
StartIndex = LBound(aData)
End Function
Public Function StopIndex()
StopIndex = UBound(aData)
End Function
Public Sub Delete(iPos)
'Make sure iPos is within acceptable ranges
If iPos < LBound(aData) or iPos > UBound(aData) then
Exit Sub 'Invalid range
End If
Dim iLoop
For iLoop = iPos to UBound(aData) - 1
aData(iLoop) = aData(iLoop + 1)
Next
Redim Preserve aData(UBound(aData) - 1)
End Sub
'****************************************
End Class
' -----------------------------------------------------------------------------
' DECLARE CLASS TO HOLD EACH RECORD OR PERMISSIONS
' -----------------------------------------------------------------------------
Class Record
Public Folder
Public Perms
'********* EVENT HANDLERS ************
Private Sub Class_Initialize()
'Allocate the dynamic array instance
Set Perms = New DynamicArray
Folder = ""
'WScript.Echo "Created new Record Class Object."
End Sub
Private Sub Class_Terminate()
Set Perms = Nothing 'Clean up!
'WScript.Echo "Deleted Record Class Object."
End Sub
'*************************************
End Class
'-----------------------------------------------------------------------------------Set R = New RecordSet P = New PermRecP.Group = "TestGroup"P.Domain = "testDomain"P.Perm = "F"R.Folder = "TestFolder"'Set R.Perms.Data(0) = PR.Perms.Data(0) = P
.
- Follow-Ups:
- Re: Classes and Arrays
- From: Michael Harris \(MVP\)
- Re: Classes and Arrays
- Prev by Date: Re: MapNetworkDrive problem
- Next by Date: Re: Classes and Arrays
- Previous by thread: WMI Script to Set The EnableDaylightSavingsTime
- Next by thread: Re: Classes and Arrays
- Index(es):
Relevant Pages
|