Solved

# Populate an array with a recursive procedure

Posted on 2006-05-11
Medium Priority
232 Views
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
Question by:markp99
• 2

LVL 65

Expert Comment

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

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

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

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

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
Course of the Month16 days, 15 hours left to enroll