|
-
May 6th, 2017, 06:05 PM
#1
Thread Starter
New Member
Pass Button Name to Function
Hi,
I'm using the below code to clear a user attribute in Active Directory when a button is clicked. I have several of these buttons (1 each for title, department, address, city, state, zip, country, phone). I could just have the same code below for each of the 8 button clicks. However, I thought it might be cleaner, and reduce the amount of code, to pass the name of each button to a single sub routine, so you only need it once, not 8 times, and then use
Code:
dirEntryResults.Properties("btnName").Clear()
. However, I can't see if it's possible to pass the button name to a sub routine? Is this possible, and if so, how?
Code:
Private Sub ClearTitle_Click(sender As Object, e As EventArgs) Handles ClearTitle.Click
Dim ADName As String = GetLogonName()
Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
dirSearcher.Filter = "(&(objectClass=user)(objectCategory=person)(sAMAccountName=test.account))"
dirSearcher.SearchScope = SearchScope.Subtree
Dim searchResults As SearchResult = dirSearcher.FindOne()
If Not searchResults Is Nothing Then
Dim dirEntryResults As New DirectoryEntry(searchResults.Path)
dirEntryResults.Properties("title").Clear()
dirEntryResults.CommitChanges()
dirEntryResults.Close()
MsgBox("Attribute Cleared", MsgBoxStyle.OkOnly, "Success")
End If
dirEntry.Close()
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|