So, I've been applying some recursive techniques to the second version of my app. This recursive procedure simply iterates through all nodes in a tree view and tests whether the text in the "department text box" matches the text name of a particular node. If there is a match, then the user's name, stored in the "name" variable, is added as a node to the node that has the same name as the department text box text.
CODE
CallTestForMatch(TreeView1)
Private Sub TestForMatch(ByVal n As TreeNode)
Dim aNode As TreeNode
Dim building1 As String = CStr(building_ComboBox.SelectedItem)
Dim department1 As String = CStr(department_ComboBox.SelectedItem)
Dim name As String = ((last_name_TextBox.Text) & ", " & (first_name_TextBox.Text))
If n.Text = department1 Then
n.Nodes.Add(name)
Exit Sub
End If
For Each aNode In n.Nodes
TestForMatch(aNode)
Next
End Sub
Private Sub CallTestForMatch(ByVal aTreeView As TreeView)
Dim node As TreeNode
For Each node In aTreeView.Nodes
TestForMatch(node)
Next
End Sub
The only problem is, when a match is found, and the name variable is added to the TreeView as a new node, I want to Exit out of the recursive procedure with the Exit Sub statement. Unfortunately, it doesn't happen. Even when a match is found, the program keeps iterating through every single node until all nodes have been examined. Is there another Keyword I can use to exit the recursive procedure? Do I need to create another procedure to get out of the recursive one?
I'm lost right now.