?
Solved

Populate an array with a recursive procedure

Posted on 2006-05-11
3
Medium Priority
?
232 Views
Last Modified: 2012-08-13
I have a routine that will collect Node.KEY values from a multi-node TreeView using a recursive procedure (ensures all nodes below the selected node are captured - node depth is indeterminate).

Question:  I want to populate the Node.KEY value into an array that I will dump to a Scratch table once the routine is complete.  This procedure is triggered by the .NodeCheck event

I am not quite sure the best way to index and populate the array via a recursive function.

Notes:  

1.  NodeCheck event calls my function
2.  CheckNodes calls itself as follows:

=====================================================
Private Sub TreeStructure_NodeCheck(ByVal Node As Object)
    Dim NodeCount as Integer

    NodeCount = Me!TreeView.Nodes.Count
    CheckNodes Node, Node.Checked
End Sub
=====================================================
Private Sub CheckNodes(ByRef oParentNode As Node, ByVal bChecked As Boolean)

'Checkbox all the child nodes for the checked node

    Dim oNode As Node
    Dim txtNodeKey as String
   
    txtNodeKey=oParentNode.Key  '---> want to send this value to an array (1 X NodeCount)

    Set oNode = oParentNode.Child
    Do While Not oNode Is Nothing
        oNode.Checked = bChecked
        CheckNodes oNode, bChecked
        Set oNode = oNode.Next
    Loop
End Sub
=====================================================

 - Should I DIM the array at the NodeCheck event?
 - Set the Array Index = 0 in NodeCheck event?
 - Increment the Index in CheckNodes function?
 - Will the Array and its Index be availble to the CheckNodes function? - Make PUBLIC?



Any suggestions?
0
Comment
Question by:markp99
  • 2
3 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 16662301
urm, what if u created a module level variable

try something like this

Dim m_myNodeValues() As String
Dim m_iNodeCount As Integer

on top of your form/module

then just before your initial call to CheckNode, set the variables

    ReDim m_myNodeValues(20)
    m_iNodeCount = 0

20 would be your node code

then as you apply a value to your array, increment m_iNodeCount

useful to put validation checks in to avoid overflows

i.e.
if m_iNodeCount = ubound(m_myNodeValues) then
   debug.print "max reached"
elseif m_iNodeCount > ubound(m_myNodeValues) then
   debug.print "problem"

0
 

Author Comment

by:markp99
ID: 16662564
rr,

You have me curious about Module Level Variables.  I've not used them before; I susually go PUBLIC.

Can you elaborate just a bit?  Any special scope/delcaration concerns?


Thanks!
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 16662685
ok, public would do

if u define dim at the top of your form code, then that variable is only visible to that particular form

prefixing it with public means all forms and all modules can see it

I dont think thats necessary hence just use dim

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question