Print Page | Close Window

Nested Subroutine Problems.

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3425
Printed Date: 29 March 2026 at 1:57pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Nested Subroutine Problems.
Posted By: rlasker3
Subject: Nested Subroutine Problems.
Date Posted: 10 June 2003 at 2:03pm

I'm attempting to create a user interface for a dynamic tree view menu.

My problem is that as I check for child menus if that child HAS children then I need to re-run my subroutine for that menu. Since I don't know the potential number of nested children it is impossible for me to determine the number of recordsets I would need.

I'm stumped on the best approach. Here is my best attempt so far. This code works great if I have no more than one level of nested children. This script is in its infancy so no true functionallity exists I'm just trying to figure out how to properly nest the data for display.

========================================

Sub WriteChildren(arrChildren)

Dim RowMax, ColMax, intRow

RowMax = UBound(arrChildren,2)

ColMax = UBound(arrChildren,1)

For intRow = 0 To RowMax

Response.Write "..." & arrChildren(1, intRow) & " "

Response.Write "<br>"

'CheckForChild(arrChildren(0,intRow)) 'This bombs the page if not commented

Next

End Sub

Sub CheckForChild(mParent)

Dim arrSubMenu

rsSubMenu.Filter = "mParent='" & rsMenu("Menu_ID") & "'"

If rsSubMenu.EOF Then

'No Children

rsSubMenu.Filter = adFilterNone

Else

arrSubMenu = rsSubMenu.GetRows()

rsSubMenu.Filter = adFilterNone

WriteChildren arrSubMenu

End If

End Sub

Dim rsMenu 'RS object for top level menu items

Dim rsSubMenu 'RS object for sublevel menu items

Set rsMenu = Server.CreateObject("ADODB.Recordset")

Set rsSubMenu = Server.CreateObject("ADODB.Recordset")

 

SetConnection 'Database subroutine in seperate file

'Open Top Level RS

strSQL = "SELECT Menu_ID, mDesc, mParent, mWidth, mHeight FROM tblMenu WHERE mParent IS NULL"

OpenRecordset rsMenu, strSQL, adOpenStatic, adLockReadOnly, adCmdText

'Open Sub Level RS

strSQL = "SELECT Menu_ID, mDesc, mParent, mWidth, mHeight FROM tblMenu WHERE mParent IS NOT NULL"

OpenRecordset rsSubMenu, strSQL, adOpenStatic, adLockReadOnly, adCmdText

If Not rsMenu.EOF Then

While Not rsMenu.EOF

Response.Write rsMenu("mDesc")

WriteLinks rsMenu("Menu_ID")

CheckForChild (rsMenu("Menu_ID"))

rsMenu.MoveNext

Wend

Else

Response.Write "No Menu Items Found In Database"

End If

'All below are database subroutines in separate file

CloseandKillRecordset(rsMenu)

CloseandKillRecordset(rsSubMenu)

CloseConnection

This produces the following output:

TOP LEVEL ITEM #1
....1st CHILD TO #1
....2nd CHILD TO #1
TOP LEVEL ITEM #2
TOP LEVEL ITEM #3
....1st CHILD TO #3
....2nd CHILD TO #3
TOP LEVEL ITEM #4

etc...etc...




Replies:
Posted By: ljamal
Date Posted: 10 June 2003 at 3:02pm
Rather than to continue to open recordsets you should just call all the information in one recordset and store that recordset into an array. You can then iterate through the array and hide and display as needed. That is the method that I use for the category system at http://www.bullcitycomics.com/ - BullCityComics.com .

If you search this forum I posted some of the code for the recursive function a while back.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net