Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:45:25+00:00 2026-05-27T04:45:25+00:00

I am hopeing someone can help me here with a recursive function I have

  • 0

I am hopeing someone can help me here with a recursive function I have that is not returning either true or false as I would have espected it to. The function loops through a Active Directory group for its members and then calls itself if it encounters any groups within the membership in order to gets its members as well. I am trying to return either true or false based on if any errors were encountered but not haveing any luck at all. It appears to just hang and never return back to the primary calling sub that starts the recursive function. Below is my code I am using:

    Private Sub StartAnalysis(ByVal grp As String, ByVal grpdn As String, ByVal reqid As String)

    Dim searchedGroups As New Hashtable

    'prior work before calling sub

    searchedGroups.Add(grp, 1)
    Dim iserror As Boolean = GetGroupMembers(grpdn, searchedGroups, reqid)

    If iserror = False Then
        'do stuff
    Else
        'do stuff
    End If

    'cleanup

End Sub


    Public Function GetGroupMembers(ByVal groupSearch As String, ByVal searchedGroups As Hashtable, ByVal requestID As String) As Boolean

    Dim iserror As Boolean = False

    Try
        Dim lastQuery As Boolean = False
        Dim endLoop As Boolean = False
        Dim rangeStep As Integer = 999
        Dim rangeLow As Integer = 0
        Dim rangeHigh As Integer = rangeLow + rangeStep

        Do
            Dim range As String = "member"
            If lastQuery = False Then
                range = String.Format("member;range={0}-{1}", rangeLow, rangeHigh)
            Else
                range = String.Format("member;range={0}-*", rangeLow)
                endLoop = True
            End If

            Dim group As SearchResult = QueryObject(groupSearch, range)
            Dim groupCN As String = group.Properties("cn")(0).ToString
            If group.Properties.Contains(range) Then
                For Each member As Object In group.Properties(range)
                    Dim user As SearchResult = QueryObject(member.ToString, "member")
                    Dim userCN = user.Properties("cn")(0).ToString
                    If Not user.Properties.Contains("member") Then
                        Dim userMail = String.Empty
                        If user.Properties.Contains("mail") Then
                            userMail = user.Properties("mail")(0).ToString
                        End If

                        userCN = userCN.Replace("'", "''")
                        Dim qry As String = _
                            "INSERT INTO group_analysis_details (request_id, member_name, member_email, member_group) " & _
                            "values ('" & requestID & "', '" & userCN & "', '" & userMail & "', '" & groupCN & "')"

                        Dim sqlConn As SqlConnection = New SqlConnection(cs)
                        Dim sqlCmd As SqlCommand = New SqlCommand(qry, sqlConn)
                        sqlConn.Open()
                        sqlCmd.ExecuteNonQuery()
                        sqlConn.Close()
                        sqlCmd.Dispose()
                        sqlConn.Dispose()
                    Else
                        If Not searchedGroups.ContainsKey(userCN) Then
                            searchedGroups.Add(userCN, 1)
                            iserror = GetGroupMembers(user.Properties("distinguishedname")(0).ToString, searchedGroups, requestID)
                            If iserror = True Then Return iserror
                        Else
                            searchedGroups(userCN) += 1
                        End If
                    End If
                Next
            Else
                lastQuery = True
            End If

            If lastQuery = False Then
                rangeLow = rangeHigh + 1
                rangeHigh = rangeLow + rangeStep
            End If

        Loop While endLoop = False
        Return iserror
    Catch ex As Exception
        myEvents.WriteEntry("Error while analyzing the following group: " & groupSearch & vbCrLf & vbCrLf & _
            "Details of the error are as follows: " & ex.Message, EventLogEntryType.Error)
        Return True
    End Try

End Function

Hopefully someone can point out where I might be making my error is this.

Thanks,
Ron

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:45:25+00:00Added an answer on May 27, 2026 at 4:45 am

    Generally if you’re using a ‘Do…Loop While’ and manually setting the exit condition inside the loop it’s very easy to get stuck in an infinite loop which is what causes the program to hang.

    It looks like you’re not setting endloop = True in all circumstances. Try changing it to an Exit Do and adding one to each of the various conditions you have. A bit of trial and error will be required to get it just right.

    Also to make your life easier extract the database insert code into a seperate function and call it when needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very strange issue, that I'm hoping someone here can help me
I'm really hoping someone can help me out here. I have a DataGrid in
I have a weird problem that I am hoping someone can help me with.
I'm getting very frustrated and I'm hoping someone here can help. I have a
I am out of ideas here, so I'm hoping someone can help. Here is
im hoping someone can help me quickly with a question i have. As site
I am hoping someone can help me with a question i have relating to
I am hoping someone can help me out with a quick question I have
Alright, I am hoping someone can help me out. I apologize up front that
I've never been much for math and I'm hoping that someone can help me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.