Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Sorting an Array

Reply
 
Old 06-26-2009   #1 (permalink)
MattW


 
 

Sorting an Array

Hi all. I spent all day yesterday trying to work this out,
experimenting with the bubble code method, the datalist method, and
the ADO Recordset method. After sitting down to it again this
morning, not really any closer, it just depresses the hell out of me.
Could someone help me sort the results from this snippet? The results
it produces are fine, but they're unsorted.

Sub btnGet_Click
window.resizeTo 300,600
sUser1 = InputBox("Enter the ID of the User")
Set objUser = GetObject("WinNT://" & strUserDomain & "/" & sUser1)
Set GroupNames = objUser.Groups

'Run lookup
For Each oGroup in GroupNames
sGroups = sGroups & oGroup.Name & vbCrLf & "<br>"
Next
DataArea.InnerHTML = sGroups
End Sub

As a disclaimer, I know that this should be simple, and that I should
RTFM, and that I clearly do not understand all of the very basic
principles involved in something so amazingly simple, but I learn by
example, and as of right now I can't find any examples out there for
successfully using DataList, UBound, or the ADO Recordset field with
an LDAP query. Thanks in advance for helping me learn.

My System SpecsSystem Spec
Old 06-26-2009   #2 (permalink)
ekkehard.horner


 
 

Re: Sorting an Array

MattW schrieb:
Quote:

> Hi all. I spent all day yesterday trying to work this out,
> experimenting with the bubble code method, the datalist method, and
> the ADO Recordset method. After sitting down to it again this
> morning, not really any closer, it just depresses the hell out of me.
> Could someone help me sort the results from this snippet? The results
> it produces are fine, but they're unsorted.
>
> Sub btnGet_Click
> window.resizeTo 300,600
> sUser1 = InputBox("Enter the ID of the User")
> Set objUser = GetObject("WinNT://" & strUserDomain & "/" & sUser1)
> Set GroupNames = objUser.Groups
>
> 'Run lookup
> For Each oGroup in GroupNames
> sGroups = sGroups & oGroup.Name & vbCrLf & "<br>"
> Next
> DataArea.InnerHTML = sGroups
> End Sub
[...]
To get you started with ADO sorting:

Const adVarWChar = 202 ' 000000CA
Const adClipString = 2 ' 00000002
Const cnGNLen = 50
Const csRowSep = "<br>"

Dim aGroups : aGroups = Array( "M", "A", "Z", "N" )
Dim oRS : Set oRS = CreateObject( "ADODB.Recordset" )
oRS.Fields.Append "Fld0", adVarWChar, cnGNLen
oRS.Open
Dim sGName
For Each sGName In aGroups
oRS.AddNew
oRS.Fields( 0 ).value = sGName
oRS.UpDate
Next
oRS.Sort = "Fld0"
Dim sGroups : sGroups = oRS.GetString( adClipString, , "", csRowSep, "<NULL>" )
oRS.Close
WScript.Echo sGroups

output:

=== demoAdoSort: demo simple ADO sort =
A<br>M<br>N<br>Z<br>
=== demoAdoSort: 0 done (00:00:00) ====

My System SpecsSystem Spec
Old 06-26-2009   #3 (permalink)
MattW


 
 

Re: Sorting an Array

On Jun 26, 9:27*am, "ekkehard.horner" <ekkehard.hor...@xxxxxx>
wrote:
Quote:

> MattW schrieb:
>
>
>
Quote:

> > Hi all. *I spent all day yesterday trying to work this out,
> > experimenting with the bubble code method, the datalist method, and
> > the ADO Recordset method. *After sitting down to it again this
> > morning, not really any closer, it just depresses the hell out of me.
> > Could someone help me sort the results from this snippet? *The results
> > it produces are fine, but they're unsorted.
>
Quote:

> > Sub btnGet_Click
> > window.resizeTo 300,600
> > sUser1 = InputBox("Enter the ID of the User")
> > Set objUser = GetObject("WinNT://" & strUserDomain & "/" & sUser1)
> > Set GroupNames = objUser.Groups
>
Quote:

> > 'Run lookup
> > * For Each oGroup in GroupNames
> > * sGroups = sGroups & oGroup.Name & vbCrLf & "<br>"
> > Next
> > DataArea.InnerHTML = sGroups
> > End Sub
>
> [...]
> To get you started with ADO sorting:
>
> * *Const adVarWChar * = 202 ' 000000CA
> * *Const adClipString = * 2 ' 00000002
> * *Const cnGNLen * * *= *50
> * *Const csRowSep * * = "<br>"
>
> * *Dim aGroups : aGroups = Array( "M", "A", "Z", "N" )
> * *Dim oRS * * : Set oRS = CreateObject( "ADODB.Recordset" )
> * *oRS.Fields.Append "Fld0", adVarWChar, cnGNLen
> * *oRS.Open
> * *Dim sGName
> * *For Each sGName In aGroups
> * * * *oRS.AddNew
> * * * *oRS.Fields( 0 ).value = sGName
> * * * *oRS.UpDate
> * *Next
> * *oRS.Sort = "Fld0"
> * *Dim sGroups : sGroups = oRS.GetString( adClipString, , "", csRowSep, "<NULL>" )
> * *oRS.Close
> * *WScript.Echo sGroups
>
> output:
>
> === demoAdoSort: demo simple ADO sort =
> A<br>M<br>N<br>Z<br>
> === demoAdoSort: 0 done (00:00:00) ====- Hide quoted text -
>
> - Show quoted text -
Thank you! I'll begin experimenting with this right away.
My System SpecsSystem Spec
Old 06-26-2009   #4 (permalink)
acomputerwiz6


 
 

Re: Sorting an Array

You have to "sort it" (oRS.Sort in the example the last guy gave)
FIRST before you add it to your page.

It may require 2 loops, one to generate, sort it, another loop to post
your findings.

Example

This is a snippet from an HTA I use. I populate a select box with a
list of groups, it creates user accounts, then gives me a list of
groups I can add them to. I could do all this with AD Users and
Computers, but this sets things up for me. I have removed some extra
stuff I do with it, but it should serve as a good example of several
useful things, and your sorting is included in the GetGroupList sub.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<!
****************************************************************************>
<!* HTA Header >
<!
****************************************************************************>
<HEAD>
<TITLE>KCGO Account Manager</TITLE>
<HTA:APPLICATION
BORDER = no
APPLICATION = Yes
WINDOWSTATE = normal
ICON="User.ico"
INNERBORDER = No
SHOWINTASKBAR = Yes
MAXIMIZEBUTTON='No'
SCROLL = No
APPLICATIONNAME = "AccountMan"
SINGLEINSTANCE = "yes"
NAVIGABLE = Yes
SYSMENU = Yes
contextMenu = Yes
Caption= Yes
Quote:

>
<meta http-equiv="MSThemeCompatible" content="Yes">

<!
****************************************************************************>
<!* Begin Script >
<!
****************************************************************************>
<SCRIPT LANGUAGE="VBScript">

On Error Resume Next

Sub CloseWindow
On Error Resume Next
self.close
End Sub

Sub GetGroupList

Const ADS_SCOPE_SUBTREE = 2
strDomain = "KCGO"

Const adVarChar = 200
Const MaxCharacters = 255
Const ForReading = 1
Const ForWriting = 2

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "GroupName", adVarChar, MaxCharacters
DataList.Open


Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://" & strDomain _
& ">;(&(objectCategory=group)(!userAccountControl:
1.2.840.113556.1.4.803:=2));Name;subtree"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF
DataList.AddNew
DataList("GroupName") = objRecordSet.Fields("Name").Value
DataList.Update
objRecordSet.MoveNext
Loop

DataList.Sort = "GroupName"

DataList.MoveFirst
Do Until DataList.EOF
strText = DataList.Fields.Item("GroupName")
Set objOption = Document.createElement("OPTION")
objOption.Text = strText
objOption.Value = strText
actions.GroupListBox.Add(objOption)
DataList.MoveNext
Loop

End Sub

Sub Window_Onload

On Error Resume Next

window.resizeTo 480,534
window.moveTo 200,10

actions.disabled=false

'Gets rid of security warning
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion
\Internet Settings\Zones\1\1406", 0, "REG_DWORD"

GetGroupList

End Sub

Sub CreateUser

On Error Resume Next
If userinfo.usernamebox.value = "" Then
Msgbox "Please fill the form in first"
Else

strUserName = LCase(userinfo.usernamebox.value)
strFirstName = userinfo.fnamebox.value
strLastName = userinfo.lnamebox.value

intFirstName = Len(strFirstName)
strFirstLetter = UCase(Left(strFirstName, 1))
strRemainingLetters = LCase(Right(strFirstName, intFirstName - 1))

strFirstName = strFirstLetter & strRemainingLetters

intLastName = Len(strLastName)
strFirstLetter = UCase(Left(strLastName, 1))
strRemainingLetters = LCase(Right(strLastName, intLastName - 1))

strLastName = strFirstLetter & strRemainingLetters

Set objOU = GetObject("LDAP://OU=UserAccounts,dc=kcgo,dc=com")
Set objUser = objOU.Create("User", "cn=" & strUserName)
objUser.samAccountName = strUserName
objUser.SetInfo
objUser.SetPassword = strUserName
objUser.givenName = strFirstName
objUser.sn = strLastName
objUser.displayName = strFirstName & Space(1) & strLastName
objUser.userPrincipalName = strUserName & "@kcgo.com"
objUser.AccountDisabled = False
objUser.Mail = userinfo.emailbox.value
objUser.pwdLastSet = 0
objUser.Description = userinfo.descbox.value
objUser.scriptPath = "logonscript.vbs"
objUser.SetInfo
End If

End Sub

Sub AddToGroup
On Error Resume Next
strGroupName = actions.GroupListBox.Value
strUserName = userinfo.usernamebox.value

If strUserName = "" Then
Msgbox "Please fill the form in first"
Else
If strGroupName = "" Then
Msgbox "Please select a group first"
Else

Set objUser = GetObject("LDAP://cn=" & strUserName &
",ou=UserAccounts,dc=kcgo,dc=com")
Set objGroup = GetObject("LDAP://cn=" & strGroupName &
",cn=Users,dc=kcgo,dc=com")
objGroup.Add(objUser.ADsPath)

End If
End If

End Sub


Sub LaunchDSA

Set Shell = CreateObject("WScript.Shell")
Shell.run "dsa.msc",1,false

End Sub


Sub Fill

If userinfo.lnamebox.value = "" Then
Msgbox "Please fill in First and Last Name"
Else
userinfo.usernamebox.value = LCase(Left(userinfo.fnamebox.value,1)
& userinfo.lnamebox.value)
userinfo.emailbox.value = LCase(Left(userinfo.fnamebox.value,1) &
userinfo.lnamebox.value & "@cimlbr.com")
End If

End Sub

Sub Reseta
On Error Resume Next
Set Shell = Nothing
userinfo.fnamebox.value = ""
userinfo.lnamebox.value = ""
userinfo.descbox.value = ""
userinfo.emailbox.value = ""
userinfo.usernamebox.value = ""
Location.Reload(True)
End Sub

</SCRIPT>

<style type="text/css">
body {
background: lightblue;
color: 11AAFF;
font-family : Courier;
font-size : 14px;
font-style : bold;
height: 100%;
margin: 3px;
}

select {
width:200px;
float: left;
margin-right: 20px;
}

form {
margin: 0px;
}

input.smBtn {
font-size:12px;
font-family:Tahoma,sans-serif;
font-weight:bold;
cursor: hand;
margin: 0px;
width: 146px;
text-align: center;
}
input.actionbtn {
font-size:12px;
font-family:Tahoma,sans-serif;
font-weight:bold;
cursor: hand;
margin: 0px;
width: 146px;
padding: 0px;
text-align: center;
}

..info {
font-family : Courier-New;
font-size : 16px;
font-weight: bold;
position: static;
bottom: 0;
}

</style>


<!
****************************************************************************>
<!* End Script / Begin HTML >
<!
****************************************************************************>
</HEAD>

<!-- <BODY onkeypress='CloseWindow'> -->
<BODY>
<br/>

<form name=actions>
<input type="button" class="smBtn" onclick=LaunchDSA value="Launch AD
Users">
<input type="button" class="smBtn" name="rsetbtn" id="rsetbtn"
onclick=Reseta value="Reset Values">
<input type="button" class="smBtn" onclick=CloseWindow value="Close">
<Font color="black" size="2">
<br/><br/>

Select a group from the list:
</font>
<br/>
<hr>

<font size="3"><b>Group List</b></font>

<select size="24" name="GroupListBox" id="GroupListBox"></select>

</form>

<form name=userinfo>
<div id="BlockInfo" class="info">
First Name:<br/> <input type="text" name="fnamebox" size="20"
maxLength="20"><br/>
Last Name:<br/> <input type="text" name="lnamebox" size="20"
maxLength="20"><br/>
Description:<br/> <input type="text" name="descbox" size="30"
maxLength="100"><br/>
<br/>
<input type="button" class="actionbtn" onclick=Fill value="Default
Fill"><br/>
User Name:<br/> <input type="text" name="usernamebox" size="20"
maxLength="20"><br/>
Email Address:<br/> <input type="text" name="emailbox" size="30"
maxLength="50"><br/>
</div>
<br/>
<input type="button" class="actionbtn" name="cun" onclick=CreateUser
value="Create User">
<input type="button" class="actionbtn" name="atg" onclick=AddToGroup
value="Add to Group">

</form>

</BODY>
</HTML>

<!
****************************************************************************>
<!* End HTML >
<!
****************************************************************************>


Saved for me as CreateUsers.hta



PS. I learned a LOT from http://www.rlmueller.net/ so thanks
Richard for posting your wonderful stuff!
My System SpecsSystem Spec
Old 06-26-2009   #5 (permalink)
MattW


 
 

Re: Sorting an Array

On Jun 26, 10:53*am, acomputerwiz6 <acomputer...@xxxxxx> wrote:
Quote:

> You have to "sort it" *(oRS.Sort in the example the last guy gave)
> FIRST before you add it to your page.
>
> It may require 2 loops, one to generate, sort it, another loop to post
> your findings.
>
> Example
>
> This is a snippet from an HTA I use. *I populate a select box with a
> list of groups, it creates user accounts, then gives me a list of
> groups I can add them to. *I could do all this with AD Users and
> Computers, but this sets things up for me. *I have removed some extra
> stuff I do with it, but it should serve as a good example of several
> useful things, and your sorting is included in the GetGroupList * sub.
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
> TR/html4/strict.dtd">
> <html>
> <!
> *****************************************************************************>
> <!* HTA Header >
> <!
> *****************************************************************************>
> <HEAD>
> <TITLE>KCGO Account Manager</TITLE>
> <HTA:APPLICATION
> BORDER = no
> APPLICATION = Yes
> WINDOWSTATE = normal
> ICON="User.ico"
> INNERBORDER = No
> SHOWINTASKBAR = Yes
> MAXIMIZEBUTTON='No'
> SCROLL = No
> APPLICATIONNAME = "AccountMan"
> SINGLEINSTANCE = "yes"
> NAVIGABLE = Yes
> SYSMENU = Yes
> contextMenu = Yes
> Caption= Yes
>
>
>
> <meta http-equiv="MSThemeCompatible" content="Yes">
>
> <!
> *****************************************************************************>
> <!* Begin Script >
> <!
> *****************************************************************************>
> <SCRIPT LANGUAGE="VBScript">
>
> On Error Resume Next
>
> Sub CloseWindow
> * On Error Resume Next
> * self.close
> End Sub
>
> Sub GetGroupList
>
> Const ADS_SCOPE_SUBTREE = 2
> strDomain = "KCGO"
>
> Const adVarChar = 200
> Const MaxCharacters = 255
> Const ForReading = 1
> Const ForWriting = 2
>
> Set DataList = CreateObject("ADOR.Recordset")
> DataList.Fields.Append "GroupName", adVarChar, MaxCharacters
> DataList.Open
>
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = * CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOObject"
> objConnection.Open "Active Directory Provider"
>
> Set objCOmmand.ActiveConnection = objConnection
> objCommand.CommandText = _
> * * "<LDAP://" & strDomain _
> * * & ">;(&(objectCategory=group)(!userAccountControl:
> 1.2.840.113556.1.4.803:=2));Name;subtree"
> objCommand.Properties("Page Size") = 1000
> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> Set objRecordSet = objCommand.Execute
>
> objRecordSet.MoveFirst
>
> Do Until objRecordSet.EOF
> * * DataList.AddNew
> * * DataList("GroupName") = objRecordSet.Fields("Name").Value
> * * DataList.Update
> * * objRecordSet.MoveNext
> Loop
>
> DataList.Sort = "GroupName"
>
> DataList.MoveFirst
> Do Until DataList.EOF
> * * strText = DataList.Fields.Item("GroupName")
> * Set objOption = Document.createElement("OPTION")
> * objOption.Text = strText
> * objOption.Value = strText
> * actions.GroupListBox.Add(objOption)
> * * DataList.MoveNext
> Loop
>
> End Sub
>
> Sub Window_Onload
>
> * * On Error Resume Next
>
> * * * * window.resizeTo 480,534
> * * * * window.moveTo 200,10
>
> * * * * actions.disabled=false
>
> * * * * 'Gets rid of security warning
> * * * * Set objShell = CreateObject("WScript.Shell")
> * * * * objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion
> \Internet Settings\Zones\1\1406", 0, "REG_DWORD"
>
> * * * * GetGroupList
>
> End Sub
>
> Sub CreateUser
>
> * * * * On Error Resume Next
> * If userinfo.usernamebox.value = "" Then
> * * Msgbox "Please fill the form in first"
> * Else
>
> * * * * strUserName = LCase(userinfo.usernamebox.value)
> * * * * strFirstName = userinfo.fnamebox.value
> * * * * strLastName = userinfo.lnamebox.value
>
> * * * * intFirstName = Len(strFirstName)
> * * * * strFirstLetter = UCase(Left(strFirstName, 1))
> * * * * strRemainingLetters = LCase(Right(strFirstName, intFirstName - 1))
>
> * * * * strFirstName = strFirstLetter & strRemainingLetters
>
> * * * * intLastName = Len(strLastName)
> * * * * strFirstLetter = UCase(Left(strLastName, 1))
> * * * * strRemainingLetters = LCase(Right(strLastName, intLastName - 1))
>
> * * * * strLastName = strFirstLetter & strRemainingLetters
>
> * * * * Set objOU = GetObject("LDAP://OU=UserAccounts,dc=kcgo,dc=com")
> * * * * Set objUser = objOU.Create("User", "cn=" & strUserName)
> * * * * objUser.samAccountName = strUserName
> * * * * objUser.SetInfo
> * * * * objUser.SetPassword = strUserName
> * * * * objUser.givenName = strFirstName
> * * * * objUser.sn = strLastName
> * * * * objUser.displayName = strFirstName & Space(1) & strLastName
> * * * * objUser.userPrincipalName = strUserName & "@kcgo.com"
> * * * * objUser.AccountDisabled = False
> * * * * objUser.Mail = userinfo.emailbox.value
> * * * * objUser.pwdLastSet = 0
> * * * * objUser.Description = userinfo.descbox.value
> * * * * objUser.scriptPath = "logonscript.vbs"
> * * * * objUser.SetInfo
> * End If
>
> End Sub
>
> Sub AddToGroup
> On Error Resume Next
> strGroupName = actions.GroupListBox.Value
> strUserName = userinfo.usernamebox.value
>
> * If strUserName = "" Then
> * * Msgbox "Please fill the form in first"
> * Else
> * * * * If strGroupName = "" Then
> * * * * * * * * Msgbox "Please select a group first"
> * * * * Else
>
> * * * * Set objUser = GetObject("LDAP://cn=" & strUserName &
> ",ou=UserAccounts,dc=kcgo,dc=com")
> * * Set objGroup = GetObject("LDAP://cn=" & strGroupName &
> ",cn=Users,dc=kcgo,dc=com")
> * * objGroup.Add(objUser.ADsPath)
>
> * * * * End If
> * End If
>
> End Sub
>
> Sub LaunchDSA
>
> * * * * * * * * Set Shell = CreateObject("WScript.Shell")
> * * * * * * * * Shell.run "dsa.msc",1,false
>
> End Sub
>
> Sub Fill
>
> * If userinfo.lnamebox.value = "" Then
> * * Msgbox "Please fill in First and Last Name"
> * Else
> * * userinfo.usernamebox.value = LCase(Left(userinfo.fnamebox.value,1)
> & userinfo.lnamebox.value)
> * * userinfo.emailbox.value = LCase(Left(userinfo.fnamebox.value,1)&
> userinfo.lnamebox.value & "@cimlbr.com")
> * End If
>
> End Sub
>
> Sub Reseta
> * * On Error Resume Next
> * * Set Shell = Nothing
> * * * * userinfo.fnamebox.value = ""
> * * * * userinfo.lnamebox.value = ""
> * * * * userinfo.descbox.value = ""
> * * * * userinfo.emailbox.value = ""
> * * * * userinfo.usernamebox.value = ""
> * * Location.Reload(True)
> End Sub
>
> </SCRIPT>
>
> <style type="text/css">
> body {
> * background: lightblue;
> * color: 11AAFF;
> * font-family : Courier;
> * font-size : 14px;
> * font-style : bold;
> * height: 100%;
> * margin: 3px;
>
> }
>
> select {
> * * * * width:200px;
> * * * * float: left;
> * * * * margin-right: 20px;
>
> }
>
> form {
> * margin: 0px;
>
> }
>
> input.smBtn {
> * font-size:12px;
> * font-family:Tahoma,sans-serif;
> * font-weight:bold;
> * cursor: hand;
> * margin: 0px;
> * width: 146px;
> * text-align: center;}
>
> input.actionbtn {
> * font-size:12px;
> * font-family:Tahoma,sans-serif;
> * font-weight:bold;
> * cursor: hand;
> * margin: 0px;
> * width: 146px;
> * padding: 0px;
> * text-align: center;
>
> }
>
> .info {
> * font-family : Courier-New;
> * font-size : 16px;
> * font-weight: bold;
> * position: static;
> * bottom: 0;
>
> }
>
> </style>
>
> <!
> *****************************************************************************>
> <!* End Script / Begin HTML >
> <!
> *****************************************************************************>
> </HEAD>
>
> <!-- <BODY onkeypress='CloseWindow'> -->
> <BODY>
> <br/>
>
> <form name=actions>
> <input type="button" class="smBtn" onclick=LaunchDSA value="Launch AD
> Users">
> <input type="button" class="smBtn" name="rsetbtn" id="rsetbtn"
> onclick=Reseta value="Reset Values">
> <input type="button" class="smBtn" onclick=CloseWindow value="Close">
> <Font color="black" size="2">
> <br/><br/>
>
> Select a group from the list:
> </font>
> <br/>
> <hr>
>
> <font size="3"><b>Group List</b></font>
>
> <select size="24" name="GroupListBox" id="GroupListBox"></select>
>
> </form>
>
> <form name=userinfo>
> <div id="BlockInfo" class="info">
> First Name:<br/> <input type="text" name="fnamebox" size="20"
> maxLength="20"><br/>
> Last Name:<br/> <input type="text" name="lnamebox" size="20"
> maxLength="20"><br/>
> Description:<br/> <input type="text" name="descbox" size="30"
> maxLength="100"><br/>
> <br/>
> <input type="button" class="actionbtn" onclick=Fill value="Default
> Fill"><br/>
> User Name:<br/> <input type="text" name="usernamebox" size="20"
> maxLength="20"><br/>
> Email Address:<br/> <input type="text" name="emailbox" size="30"
> maxLength="50"><br/>
> </div>
> <br/>
> <input type="button" class="actionbtn" name="cun" onclick=CreateUser
> value="Create User">
> <input type="button" class="actionbtn" name="atg" onclick=AddToGroup
> value="Add to Group">
>
> </form>
>
> </BODY>
> </HTML>
>
> <!
> *****************************************************************************>
> <!* End HTML >
> <!
> *****************************************************************************>
>
> Saved for me as * CreateUsers.hta
>
> PS. *I learned a LOT fromhttp://www.rlmueller.net/* so thanks
> Richard for posting your wonderful stuff!
Thank you!
My System SpecsSystem Spec
Old 06-26-2009   #6 (permalink)
ekkehard.horner


 
 

Re: Sorting an Array

acomputerwiz6 schrieb:
Quote:

> You have to "sort it" (oRS.Sort in the example the last guy gave)
> FIRST before you add it to your page.
>
> It may require 2 loops, one to generate, sort it, another loop to post
> your findings.
>
Especially if you need a HTML representation of the recordset's
data, you can avoid the second (concatenate/display) loop by using
..GetString()

[...]
My System SpecsSystem Spec
Old 06-26-2009   #7 (permalink)
acomputerwiz6


 
 

Re: Sorting an Array

On Jun 26, 1:12*pm, "ekkehard.horner" <ekkehard.hor...@xxxxxx>
wrote:
Quote:

> acomputerwiz6 schrieb:> You have to "sort it" *(oRS.Sort in the examplethe last guy gave)
Quote:

> > FIRST before you add it to your page.
>
Quote:

> > It may require 2 loops, one to generate, sort it, another loop to post
> > your findings.
>
> Especially if you need a HTML representation of the recordset's
> data, you can avoid the second (concatenate/display) loop by using
> .GetString()
>
> [...]
Care to elaborate a little bit?
My System SpecsSystem Spec
Old 06-26-2009   #8 (permalink)
ekkehard.horner


 
 

Re: Sorting an Array

acomputerwiz6 schrieb:
Quote:

> On Jun 26, 1:12 pm, "ekkehard.horner" <ekkehard.hor...@xxxxxx>
> wrote:
Quote:

>> acomputerwiz6 schrieb:> You have to "sort it" (oRS.Sort in the example the last guy gave)
Quote:

>>> FIRST before you add it to your page.
>>> It may require 2 loops, one to generate, sort it, another loop to post
>>> your findings.
>> Especially if you need a HTML representation of the recordset's
>> data, you can avoid the second (concatenate/display) loop by using
>> .GetString()
>>
>> [...]
>
> Care to elaborate a little bit?

MattW's code

For Each oGroup in GroupNames
sGroups = sGroups & oGroup.Name & vbCrLf & "<br>"
Next
DataArea.InnerHTML = sGroups

used a loop to concatenate the data from the source collection
(objUser.Groups) into a HTML string. To sort the data, a loop
to transfer the info into a sortable collection seems to be
unavoidable. My code

For Each sGName In aGroups
oRS.AddNew
oRS.Fields( 0 ).value = sGName
oRS.UpDate
Next

does that for an ADO recordset. A similar loop could be used to
fill (add to) a "System.Collections.ArrayList". As your remark
Quote:
Quote:
Quote:

>>> It may require 2 loops, one to generate, sort it, another loop to post
>>> your findings.
indicates, the possibility to streamline the code by using .GetString()

http://msdn.microsoft.com/en-us/libr...75(VS.85).aspx

(or Join( oArrayList.ToArray(), "<WhatEver>" )) is easily overlooked.



My System SpecsSystem Spec
Old 06-26-2009   #9 (permalink)
acomputerwiz6


 
 

Re: Sorting an Array

On Jun 26, 2:59*pm, "ekkehard.horner" <ekkehard.hor...@xxxxxx>
wrote:
Quote:

> acomputerwiz6 schrieb:
>
Quote:

> > On Jun 26, 1:12 pm, "ekkehard.horner" <ekkehard.hor...@xxxxxx>
> > wrote:
Quote:

> >> acomputerwiz6 schrieb:> You have to "sort it" *(oRS.Sort in the example the last guy gave)
> >>> FIRST before you add it to your page.
> >>> It may require 2 loops, one to generate, sort it, another loop to post
> >>> your findings.
> >> Especially if you need a HTML representation of the recordset's
> >> data, you can avoid the second (concatenate/display) loop by using
> >> .GetString()
>
Quote:
Quote:

> >> [...]
>
Quote:

> > Care to elaborate a little bit?
>
> MattW's code
>
> * *For Each oGroup in GroupNames
> * * *sGroups = sGroups & oGroup.Name & vbCrLf & "<br>"
> * *Next
> * *DataArea.InnerHTML = sGroups
>
> used a loop to concatenate the data from the source collection
> (objUser.Groups) into a HTML string. To sort the data, a loop
> to transfer the info into a sortable collection seems to be
> unavoidable. My code
>
> * *For Each sGName In aGroups
> * * * *oRS.AddNew
> * * * *oRS.Fields( 0 ).value = sGName
> * * * *oRS.UpDate
> * *Next
>
> does that for an ADO recordset. A similar loop could be used to
> fill (add to) a "System.Collections.ArrayList". As your remark
>
> *>>> It may require 2 loops, one to generate, sort it, another loop to post
> *>>> your findings.
>
> indicates, the possibility to streamline the code by using .GetString()
>
> * *http://msdn.microsoft.com/en-us/libr...75(VS.85).aspx
>
> (or Join( oArrayList.ToArray(), "<WhatEver>" )) is easily overlooked.
I see, I am still learning as well, my code isn't always the cleanest,
but I always run across better ways of doing things all the time.
Makes it fun that way too.
My System SpecsSystem Spec
Old 06-30-2009   #10 (permalink)
MattW


 
 

Re: Sorting an Array

Okay, sorry for the delay, guys, my day to day functions got a little
crowded. Here's what I'm trying now, from the previously posted code:

Code:
Sub btnGet_Click
window.resizeTo 300,600

Const adVarWChar   = 202 ' 000000CA
Const adClipString =   2 ' 00000002
Const cnGNLen      =  50
Const csRowSep     = "<br>"

Dim Datalist
Set Datalist = CreateObject("ADODB.Recordset")
DataList.Fields.Append "GroupName", adVarWChar, cnGNLen
DataList.Open
sUser1 = InputBox("Enter the ID of the User")
Set objUser = GetObject("WinNT://" & strUserDomain & "/" & sUser1)
Set GroupNames = objUser.Groups

'Run lookup
For Each oGroup in GroupNames
Datalist.AddNew
Datalist.Fields(0).value = oGroup
Datalist.Update
Next
Datalist.Sort = "GroupName"
sGroups = Datalist.GetString(adClipString,,"",csRowSep,"<NULL>")
Datalist.Close

DataArea.InnerHTML = sGroups
End Sub
I'm getting a "Member not found" error on

Datalist.Fields(0).value = oGroup

Heading to google, but thought I'd keep the discussion updated.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Fast copy method of sub array (=array range) possible? VB Script
How to create array without quotes? $array = (a,b,c) PowerShell
Stupid Array Tricks: Initializing an Array to a Certain Size PowerShell
Sorting an array on pattern? PowerShell
how to assign values to array and how to create array via variable PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46