Classes _asp class class for generating directory tree structure under ASP
Source: Internet
Author: User
About classes that generate a directory tree structure
This program has two files test.asp and tree.asp and some icon files
1. The test.asp call class generates the tree code as follows
<%@ Language=vbscript%>
<link rel= "stylesheet" href= "Tree.css" >
<title>tree</title>
<!--#include file= "tree.asp"-->
<%
'========================================
' Building A Tree programatically
'========================================
' This approach would is best suited for building
' Dynamic trees using for.. Next loops and such.
Set MyTree2 = New Tree
Mytree2.top = 10
Mytree2.left = 10
Mytree2.expandimage = "Plus.gif"
Mytree2.collapseimage = "Minus.gif"
Mytree2.leafimage = "Webpage.gif"
' Notice the indentation used to reprensent the hierarchy
Set Node1 = mytree2.createchild ("script")
Set SubNode1 = node1.createchild ("server")
Set secSubNode1 = subnode1.createchild ("html")
Secsubnode1.createchild "<a href=" "HTTP://127.0.0.1/" ">asp</A>"
Secsubnode1.createchild "<a href=" "HTTP://127.0.0.1/" ">php</A>"
Secsubnode1.createchild "<a href=" "HTTP://127.0.0.1/" ">jsp</A>"
Set Node2 = Mytree2.createchild ("Desktop")
Node2.createchild "<a href=" "#" ">area Code lookup</a>"
Node2.createchild "<a href=" "#" ">arin Based Whois search</a>"
Node2.createchild "<a href=" "#" ">world Time Zone map</a>"
Mytree2.draw ()
Set MyTree2 = Nothing
%>
</BODY>
</HTML>
2. The definition code for the Tree.asp class is as follows
<%
'******************************************************
' Author:jacob Gilley
' Email:avis7@airmail.net
' My terms:you can-control ' anyway for you
' Cause I have no means to enforce any guidelines
' or BS that most developers to they can get
' You'll agree to by spouting out words like
' Intellectual property ' and ' The Code Gods '.
'-Viva la microsoft!
'******************************************************
Dim Gbltreenodecount:gbltreenodecount = 1
Class TreeNode
Public Value
Public Expandimage
Public Collapseimage
Public Leafimage
Public Expanded
Private Mszname
Private Mcolchildren
Private mbchildreninitialized
Public Property Get ChildCount ()
ChildCount = Mcolchildren.count
End Property
mbchildreninitialized = False
Expanded = False
End Sub
Private Sub Class_Terminate ()
If mbchildreninitialized and IsObject (Mcolchildren) Then
Mcolchildren.removeall ()
Set Mcolchildren = Nothing
End If
End Sub
Private Sub initchildlist ()
Set Mcolchildren = Server.CreateObject ("Scripting.Dictionary")
mbchildreninitialized = True
End Sub
Private Sub LoadState ()
If request (Mszname) = "1" Or Request ("togglenode") = Mszname Then
Expanded = True
End If
End Sub
Public Function Createchild (szvalue)
If not mbchildreninitialized Then initchildlist ()
Set createchild = New TreeNode
Createchild.value = Szvalue
Createchild.expandimage = Expandimage
Createchild.collapseimage = Collapseimage
Createchild.leafimage = Leafimage
Public Sub loadtemplate (szFileName)
Dim Objworkingnode
Dim Colnodestack
Dim Fsobj, Tsobj
Dim Szline
Dim Ncurrdepth, Nnextdepth
Set colnodestack = Server.CreateObject ("Scripting.Dictionary")
Set fsobj = CreateObject ("Scripting.FileSystemObject")
Set tsobj = Fsobj.opentextfile (szFileName, 1)
ncurrdepth = 0
While not tsobj.atendofline
Nnextdepth = 1
Szline = Tsobj.readline ()
If ncurrdepth = 0 Then
Set Objworkingnode = Createchild (Trim (szline))
Ncurrdepth = 1
Else
While Mid (szline,nnextdepth,1) = VbTab Or Mid (szline,nnextdepth,1) = ""
nnextdepth = nnextdepth + 1
Wend
If nnextdepth > 1 Then szline = Trim (Mid (szline,nnextdepth))
If szline <> "" Then
If nnextdepth > Ncurrdepth Then
If colnodestack.exists (ncurrdepth) Then
Set Colnodestack.item (ncurrdepth) = Objworkingnode
Else
Colnodestack.add Ncurrdepth, Objworkingnode
End If
Set Objworkingnode = Objworkingnode.createchild (szline)
ncurrdepth = ncurrdepth + 1
ElseIf nnextdepth <= ncurrdepth Then
If nnextdepth > 1 Then
Nnextdepth = nNextDepth-1
While not colnodestack.exists (nnextdepth) and nnextdepth > 1
Nnextdepth = nNextDepth-1
Wend
Set Objworkingnode = Colnodestack.item (nnextdepth)
Set Objworkingnode = Objworkingnode.createchild (szline)
nnextdepth = nnextdepth + 1
Else
Set Objworkingnode = Createchild (szline)
End If
Ncurrdepth = nnextdepth
End If
End If
End If
Wend
Tsobj.close ()
Set tsobj = Nothing
Set fsobj = Nothing
Colnodestack.removeall ()
Set Colnodestack = Nothing
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.