Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Nested Subroutine Problems.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Nested Subroutine Problems.

 Post Reply Post Reply
Author
rlasker3 View Drop Down
Newbie
Newbie


Joined: 10 June 2003
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote rlasker3 Quote  Post ReplyReply Direct Link To This Post Topic: Nested Subroutine Problems.
    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...

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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 BullCityComics.com.

If you search this forum I posted some of the code for the recursive function a while back.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.