Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2004, 04:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default Class newbie problem

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!
__________________
- mega
Aspiring JavaScript Ninja
 
Old March 3rd, 2004, 04:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

I don't get any error message from ASP, the browser just hang.

 - mega
 
Old March 4th, 2004, 05:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

How about putting () after Functions and Property Get's that don't take any arguments.

Also:
1. Set objFolder = objFSO.GetFolder(PhysicalPath) is in your Class_Initialize, but there won't be any value in PhysicalPath at that stage will there?
2. If PhysicalPath <> "" Then
        Err.Raise vbObjectError + 24, "cFolders.asp", "Physical Path is empty"
      End If
isn't that the wrong way around? If PhysicalPath = "" it's empty!
 
Old March 4th, 2004, 06:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

your right..
1. I didn't see that at all thanks.
2. Had a NOT statement just before I posted this.. But you know, when nothing work you just gotta try everything.
I don't think putting () would have any effect, but I'll do anyway.
I'll get back to your all, after I tried this.
Thanks!

 - mega





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Problem - Newbie jackiew SQL Server 2000 3 October 14th, 2008 07:44 PM
record add problem newbie here jdsflash ASP.NET 1.0 and 1.1 Basics 3 May 19th, 2006 12:04 PM
Newbie question on the 2nd ed: Class inheritance elde BOOK: Professional C#, 2nd and 3rd Editions 0 December 9th, 2004 03:00 AM
Stored Proc. problem - newbie joeb SQL Server 2000 5 November 22nd, 2004 06:18 AM
MSDE connection problem (Newbie) rahzan SQL Server 2000 2 June 29th, 2004 08:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.