开发者

Returning multiple values from a function call

I have an active directory search function:

    Function GetAdInfo(ByVal ADDN As String, ByVal ADCommonName As String, ByVal ADGivenName As String, ByVal ADStaffNum As String, ByVal ADEmail As String, ByVal ADDescription As String, ByVal ADTelephone As String, ByVal ADOffice As String, ByVal ADEmployeeID As String) As String
        Dim netBIOSname As String = Me.Request.LogonUserIdentity.Name
        Dim sAMAccountName As String = netBIOSname.Substring(netBIOSname.LastIndexOf("\"c) + 1)
        Dim defaultNamingContext As String
        Using rootDSE As DirectoryServices.DirectoryEntry = New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
            defaultNamingContext = rootDSE.Properties("defaultNamingContext").Value.ToString()
        End Using
        Using searchRoot As DirectoryServices.DirectoryEntry = _
                            New DirectoryServices.DirectoryEntry("LDAP://" + defaultNamingContext, _
                                "kingkong", "kingkong", DirectoryServices.AuthenticationTypes.Secure)
            Using ds As DirectoryServices.DirectorySearcher = New DirectoryServices.DirectorySearcher(searchRoot)
                ds.Filter = String.Format("(&(objectClass=user)(objectCategory=person)(sAMAccountName={0}))", sAMAccountName)
                Dim sr As DirectoryServices.SearchResult = ds.FindOne()

                ADDN = (sr.Properties("displayName")(0).ToString())
                ADCommonName = (sr.Properties("cn")(0).ToString())
                ADGivenName = (sr.Properties("givenname")(0).ToString())
                ADStaffNum = (sr.Properties("sn")(0).ToString())
                ADEmail = (sr.Properties("mail")(0).ToString())
                ADDescription = (sr.Properties("description")(0).ToString())
                ADTelephone = (sr.Properties("telephonenumber")(0).ToString())
                ADOffice = (sr.Properties("physicalDeliveryOfficeName")(0).ToString())

            End Using
        End Using
        Return ADDN
        Return ADCommonName
        Return ADGivenName
        Return ADStaffNum
        Return ADEmail
        Return ADDescription
        Return ADTelephone
        Return ADOffice

The function appears to work, as when I put a breakpoint at the end, the variables such as ADDN do have the correct values.

Then I call the function in my page_load like this:

GetAdInfo(ADDN, ADCommonName, ADGivenName, ADStaffnum, ADEmail, ADDescription, ADTelephone, ADOffice, ADEmployeeID)

Then I try to response.write out one of the vars to test like this:

Response.Write(ADDN) 

But the value is empty.

Please can someone tell me what I am d开发者_JAVA技巧oing wrong. Thanks


You can only return a single value from a function - you can pass these by reference and they should come back with the correct values, but for me, I think you'd be better creating a small class with the properties you need returned, and return an instance of that class from this method, populated with the returned variables - this means you'll have fewer problems changing this method if you have to add more return values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜