Hi all.
This is my first attempt to write a VBScript class and I don't know where the error is. I'll post the code so that you guys might trap it (The red piece of code is where I think the problem is):
Code:
<%
Class cFolders
' Const ERRNoPath = vbObjectError + 24
Private objFolder
Private objFSO
Private PhysicalPath
Private m_PhysicalPath
Public Property Let PhysicalPath(strFolder)
m_PhysicalPath = Server.MapPath(strFolder)
End Property
Public Property Get PhysicalPath
PhysicalPath = m_PhysicalPath
If PhysicalPath <> "" Then
Err.Raise vbObjectError + 24, "cFolders.asp", "Physical Path is empty"
End If
End Property
Private Sub Class_Initialize()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(PhysicalPath)
End Sub
Private Sub Class_Terminate()
Set objFolder = Nothing
Set objFSO = Nothing
End Sub
Private Function CountCollection(varCollection)
Dim MyItem
For Each MyItem In varCollection
CountCollection = CountCollection + 1
Next
End Function
Private Function MakeImg(strLink,strALT)
MakeImg = "<img src='" & strLink
MakeImg = MakeImg & "' alt='" & strALT
MakeImg = MakeImg & "' />"
End Function
Private Function MakeLink(strLink,intNoofFiles)
MakeLink = "<a href='?Folder="
MakeLink = MakeLink & strLink & "'>" & strLink
MakeLink = MakeLink & "(" & intNoofFiles & ")</a>"
End Function
Public Function ListFolders
Dim myFolder, intCount, strName
For Each myFolder In objFolder.SubFolders
If NOT myFolder.Attributes = "Hidden" Then
intCount = CountCollection(myFolder.Files)
strName = myFolder.Name
ListFolders = ListFolders & (MakeLink(CStr(strName), CInt(intCount)) & "<br>")
End If
Next
End Function
Public Function ListImages
Dim Image
For Each Image In objFiles
ListImages = ListImages & ImageDir & Image.Name
Next
End Function
End Class
%>
This is how I use cFolders:
Code:
Dim objFolders
Response.Write("Create Object...<p />")
Set objFolders = New cFolders
Response.Write("Set Folder path...<p />")
objFolder.PhysicalPath = "Pic"
Response.Write("Make list of folders...<p />")
Response.Write (objFolders.ListFolders)
Response.Write("<p>Finish!</p>")
Set objFolders = Nothing
Any help would be greatly appreciated!