Classes and Arrays



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

.



Relevant Pages

  • Re: Excel temporary files
    ... but temp files get left. ... 'we use an array and store the file objects as this avoids any problems ... 'now go back and delete empty folders below the temp folder ... Sub SelectFiles ...
    (microsoft.public.excel)
  • Re: Dateien und Folder löschen
    ... > ich suche ein Programm oder Script was in einem Folder alle Daten und ... > Der root folder soll aber nicht gelöscht werden. ... 'we use an array and store the file objects. ... sub SelectFiles ...
    (microsoft.public.de.german.scripting.wsh)
  • Re: File name changes on opening - adds a number to end
    ... Here's a copy of the script that I use: ... 'we use an array and store the file objects. ... 'get the path to the temp folder ... sub SelectFiles ...
    (microsoft.public.excel.misc)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreMyOldVals ... ' store values of current row in array ... Dim dbs As DAO.Database, rst As DAO.Recordset ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: Multiple OUs?
    ... something is up with adding multiple values to the array... ... ' If the AD enumeration runs into an OU object, call the Sub again to ... strLine = Trim ... strNewContents = strNewContents & strLine & vbCrLf ...
    (microsoft.public.scripting.vbscript)