piattnd
asked on
Dynamic listbox not working properly
Experts,
I was previously assisted on this topic, however I've encountered another poblem.
My script pulls a query within AD for a list of users. It then sorts that list of users alphabetically and puts the sorted items back into the original dictionary.
I am able to post the items to the GUI, but when I begin typing out the name of a person I want to select, the script is removing the incorrect entries.
For example, if I type "Fr", anything that doesn't have (or start with) "Fr" should be removed, and the others should remain.
I've posted my code, any help would be appreciated.
I was previously assisted on this topic, however I've encountered another poblem.
My script pulls a query within AD for a list of users. It then sorts that list of users alphabetically and puts the sorted items back into the original dictionary.
I am able to post the items to the GUI, but when I begin typing out the name of a person I want to select, the script is removing the incorrect entries.
For example, if I type "Fr", anything that doesn't have (or start with) "Fr" should be removed, and the others should remain.
I've posted my code, any help would be appreciated.
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
'msgbox objRecordSet.Fields("givenName").Value & " " & objRecordSet.Fields("sn").Value
strUserAccount = UCase(objRecordSet.Fields("sAMAccountName").Value)
strUserEntry = UCase(objRecordSet.Fields("givenName").Value) & " " & UCase(objRecordSet.Fields("sn").Value)
strUserMail = objRecordSet.Fields("mail").Value
If strUserAccount = "null" OR strUserEntry = "null" OR strUserMail = null then
'skip record, do nothing
Else
dicUserNameList.Add strUserEntry,strUserAccount
End If
ObjRecordSet.MoveNext
Loop
msgbox "Entries created"
Set objDictSorted = SortDict(dicUserNameList)
window.setTimeout "BuildList()",200
End Sub
Function SortDict(ByVal objDict)
Dim i, j, temp
For Each i In objDict
For Each j In objDict
If(objDict.Item(i) <= objDict.Item(j)) Then
temp = objDict.Item(i)
objDict.Item(i) = objDict.Item(j)
objDict.Item(j) = temp
End If
Next
Next
'For Each i In objDict
'msgbox objDict.Item(i)
'Next
Set SortDict = dicUserNameList
End Function
Sub BuildList
For Each strUser in dicUserNameList
'msgbox strUser & " " & strUserEmail
Set objOption = Document.createElement("OPTION")
objOption.Text = dicUserNameList.Item(strUser)
objOption.Value = dicUserNameList.Item(strUser)
'msgbox objOption.Text & " " & objOption.Value
UserNames.Add(objOption)
Next
End Sub
Sub CheckValue
msgbox UserNames.Value
End Sub
Sub CheckKey
Set objOptions = UserNames.Options
For Each strOption in objOptions
strOption.RemoveNode
Next
If EnterName.Value = "" then
For Each strUser in dicUserNameList
'msgbox strUser & " " & strUserEmail
Set objOption = Document.createElement("OPTION")
objOption.Text = dicUserNameList.Item(strUser)
objOption.Value = dicUserNameList.Item(strUser)
'msgbox objOption.Text & " " & objOption.Value
UserNames.Add(objOption)
Next
Else
'For Each strUser in dicUserNameList
For Each strUser in objDict
strEntryLength = len(EnterName.Value)
msgbox left(strUser,strEntryLength)
If left(strUser,strEntryLength) = Ucase(EnterName.Value) then
Set objOption = Document.createElement("OPTION")
objOption.Text = dicUserNameList.Item(strUser)
objOption.Value = dicUserNameList.Item(strUser)
UserNames.Add(objOption)
Else
'Nothing, doesn't match.
End If
Next
End If
End Sub
ASKER
An update on this:
The problem lies within my "sorting" function called SortDict (I got this code on the web, was just trying it out and can't figure it out).
Still need help on sorting the dictionary out!
The problem lies within my "sorting" function called SortDict (I got this code on the web, was just trying it out and can't figure it out).
Still need help on sorting the dictionary out!
ASKER
If you don't have too many names in AD, you can add a line to the code above.
At line 97 add a line that says;
msgbox strUserEntry & "," & strUserAccount
When the HTA runs you will be looking for duplicate names - perhaps blank names? Something to test out.
At line 97 add a line that says;
msgbox strUserEntry & "," & strUserAccount
When the HTA runs you will be looking for duplicate names - perhaps blank names? Something to test out.
Since you want to sort and filter arrays, try using disconnected record sets. They offer similar features as a temporary database. You can add fields, field types and field lengths. Once you have built up your table, you will be able to sort and filter the record set for output. See below for a sample.
Here is an example which uses a disconnected record set.
https://www.experts-exchange.com/questions/23675665/How-can-I-sort-a-dynamic-multi-dimentional-array.html
Here is an example which uses a disconnected record set.
https://www.experts-exchange.com/questions/23675665/How-can-I-sort-a-dynamic-multi-dimentional-array.html
Const adVarChar = 200
Const VarCharMaxCharacters = 255
Const adFldIsNullable = 32
Set UsersDB = CreateObject("ADOR.Recordset")
UsersDB.Fields.Append "CN", adVarChar, VarCharMaxCharacters, adFldIsNullable
UsersDB.Fields.Append "DistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
UsersDB.Open
'code to loop through users in AD
UsersDB.AddNew
UsersDB("CN") = strCN
UsersDB("DistinguishedName") = strDN
UsersDB.Update
'.movenext
'loop
if txt_MyFilter.Value = "" then
UsersDB.Filter = ""
else
UsersDB.Filter = "CN LIKE '*" & txt_MyFilter.Value & "*'"
end if
UsersDB.Sort = "CN"
If UsersDB.RecordCount > 0 then
UsersDB.MoveFirst
Do Until UsersDB.EOF
strCN = UsersDB.Fields.Item("CN").Value
strDN = UsersDB.Fields.Item("DistinguishedName").Value
UsersDB.MoveNext
Loop
End if
ASKER
Unfortunately I'll be dealing with upwards of 2,000ish accounts. Joyful eh? :)
Thanks much, I'll give this second one a shot when I can. I was able to take the code i had in place, combined with your original idea, and was able to make a NON sorting solution. Now, to just figure out why sorting isn't working properly.
Thanks much, I'll give this second one a shot when I can. I was able to take the code i had in place, combined with your original idea, and was able to make a NON sorting solution. Now, to just figure out why sorting isn't working properly.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I was able to track down a friend who actually had a function that did the sort. I have yet to impliment it (haven't had time), but I appreciate your help!
ASKER
Thanks again for the help!
It will poll all users and list them in the box. The listbox automatically sorts the names so you do not need to run additional code for that. As you type in the lower text box, the names above are checked and filtered. Double click the name in the listbox to jump to that individual.
Open in new window