Create an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    Create an array

    Hello,

    My LDAP query is working. However I want to store the values in an array. Very simply put the examples online for arrays suck. Is there a very easy step by step method of creating a string array. Below is my code and what I tried to do:

    Code:
    Private Sub btn_Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Search.Click
    
            Dim UserID As String
            Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
            Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
            Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
    
    
            Dim objSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
            'Dim ADSearchResult As System.DirectoryServices.SearchResult
            Dim oResults As DirectoryServices.SearchResultCollection
            Dim oResult As DirectoryServices.SearchResult
            Dim RetArray() As String
            'Dim myresults As String
            Dim i As Integer
    
            i = 0
    
            UserID = txt_Name.Text
            objSearch.PropertiesToLoad.Add("uid")
            objSearch.PropertiesToLoad.Add("givenname")
            objSearch.PropertiesToLoad.Add("cn")
            objSearch.Filter = ("(samAccountName=*" & UserID & "*)")
            oResults = objSearch.FindAll
    
            For Each oResult In oResults
    
                RetArray(i) = oResult.GetDirectoryEntry.Properties("cn").Value
                RetArray.Sort(RetArray)
    
                lb_Names.Items.Add(RetArray)
    
    
                i = i + 1
            Next
    
        End Sub

    any help is appreicated
Working...