31290

playing with arrays and lists

49 posts in this topic

Hi everyone, 

I have an array which is populated among results found with the AD UDF. So there can be hundreds of results. This array is output in a txt file in order to read the lines:

Here's some lines:

307|3|
USERID|CN=XXXX,OU=Users,OU=SITE,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX|NAME, FIRST NAME
XXXX|CN=XXXX,OU=Users,OU=XXXX,OU=Mexico,OU=LA,DC=XXXX,DC=XXXX|XXXX XXXX
XXXX|CN=XXXX,OU=Users,OU=XXXX,OU=Argentina,OU=LA,DC=XXXX,DC=XXXX|XXXX XXXX

The first value is the number of returned results; the second one is the number of rows of the array. The file will always be outputted like the "code" above.

What I would like to achieve is to put all results in a listbox looking like the "windows explorer". I mean that it would contain 5 row that can be sorted by the "headers" (I've uploaded a photo to better explain). Also, I'd like to have the possibility to double click on a line where the value in the "User ID" would be stored in a variable (for further treatment but I know what to do with it ^^)

I know this can be a "huge" request but I've no idea where to start or how to achieve it.

Thanks in advance to all that can offer help, I'm sure my knowledge will grow :) 

Bye

Untitled.png


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites



Thanks johnOne, 

That's a good start indeed. But what miss me is how to extract data from the array and place them accordingly to my needs. 

Also, is it mandatory for me to export the array content to a file and then read the file? Seems a bit to complicated for me :/

 


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

Thanks again johnOne, 

 

That's also a very nice function that will be very handy. 

But I still don't know how to read from the array to extract only data I want to put in the list. 

Can you please help?


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

As a start i suggest the following:
Sorting isn't implemented yet.
 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $sTemp = ""
Global $aResult[][] = [[3, 3], ["USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX", "NAME1, FIRST NAME"], ["USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX", "NAME2, FIRST NAME"], ["USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX", "NAME3, FIRST NAME"]]
GUICreate("Active Directory Information", 420, 450)
Global $idListview = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
For $i = 1 To $aResult[0][0]
    $sTemp = $aResult[$i][2] & "|" & $aResult[$i][0] & "|" & $aResult[$i][1]
    GUICtrlCreateListViewItem($sTemp, $idListview)
Next
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Do you really read the data from a file? Or do you retrieve the data from AD in your script an populate an array?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi Water and thanks for your input. 

Indeed, I retrieve data right from your AD UDF by doing this: 

$aObjects = _AD_GetObjectsInOU("", "(ANR=" & $currentUser & ")", 2, "sAMAccountName,distinguishedName,displayname", "displayname")

And this array (I think this will be limited to the 500 first results if more) can have lots of results.

What annoys me the most in fact, is on how to get only the "SITE"  from "OU=SITE" and the "COUNTRY" defined by "OU=Country" (Brazil, Mexico, etc...) because it's in the same row that all the crap around.

I could have populated the array with other things with "LDAP Names" but I think OU's are the best because some other information can be forgotten by the user's creator.

Hope this is clear enough :)


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

Something like this?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <AD.au3>

; _AD_Open()
; Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & @Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
; _AD_Close()
Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp = ""
GUICreate("Active Directory Information", 420, 450)
Global $idListview = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT)
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $idListview)
Next
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

New version with sort and alternate colors:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>

; _AD_Open()
; Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & @Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
; _AD_Close()
Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water, 

WOW! That is huge! Thanks thanks thanks :)

This is exactly what I imagined!

I see you manually populated the array, is there a way to populate it right from the _AD_GetObjectsInOU("", "(ANR=" & @Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname") ?

:)


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

Sure. Remove line

Global $aResult[][] = [[3, 3], [" ...

and the comments in the 3 lines above.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water, 

 

Thanks again but I do have an error while following your instructions.

Here's the code:

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")
_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Can you please help?

24-09-2015 17-22-57.jpg


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

_AD_Open is missing at the top of your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Sorry, I forgot to paste it. I can assure you it's present. 

Here's the whole code:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $Resources &"\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"


$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
Msgbox(0,"", "NO GO") ; Ad connection results
Else
Msgbox(0,"", "GO") ; Ad connection results
Endif

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")


_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Hope it helps you :)

Edited by 31290
formatting

~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

Let's display the array that causes the error:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $Resources &"\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"


$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
Msgbox(0,"", "NO GO") ; Ad connection results
Else
Msgbox(0,"", "GO") ; Ad connection results
Endif

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")

_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
_ArrayDisplay($aTemp) ; <== This line is new
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Here's what I have when launching your script.

array.jpg

FYI: the "martin" user name has 507 results in my AD ^^

Edited by 31290
precisions

~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

That looks good. I have to check the code tomorrow when I return to my office.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Ok, sure, that's very kind of you! Have a great evening :)


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

One last idea for today. Lets check on which of the 507 records the get the error. Please run this version from SciTE so we can see the output.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Global $sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext, $iRunning, $aGroup, $sGroup, $i, $GIDInput

Global $resources = "C:\SAC_IS\AD_Toolbox\Resources\"
Global $workingDir = "C:\SAC_IS\AD_Toolbox\"
Global $logs = $Resources &"\Logs\"
Global $sIniFile = $resources & "\AD_Toolbox_" & @UserName & ".ini"


$sT0_AdminUserName = "Shhhh"
$sT0_AdminUserPassword = "Evenmoreshhhh"
$sT0_DomainName = IniRead($sIniFile, "ADTB", "DomainName", "")
$sT0_DomainController = IniRead($sIniFile, "ADTB", "DomainController", "")
$sT0_ConfigurationContext = IniRead($sIniFile, "ADTB", "ConfigurationContext", "")

_AD_Open($sT0_AdminUserName, $sT0_AdminUserPassword, $sT0_DomainName, $sT0_DomainController, $sT0_ConfigurationContext)
If @error > 0 Then
Msgbox(0,"", "NO GO") ; Ad connection results
Else
Msgbox(0,"", "GO") ; Ad connection results
Endif

$username = "martin"

Global $aResult = _AD_GetObjectsInOU("", "(ANR=" & $Username & ")", 2, "displayname,sAMAccountName,distinguishedName", "displayname")

_AD_Close()
; Global $aResult[][] = [[3, 3], ["NAME1, FIRST NAME", "USERID1", "CN=XXXX,OU=Users,OU=SITE1,OU=Brazil,OU=LA,DC=XXXX,DC=XXXX"], ["NAME2, FIRST NAME", "USERID2", "CN=XXXX,OU=Users,OU=SITE2,OU=Portugal,OU=LA,DC=XXXX,DC=XXXX"], ["NAME3, FIRST NAME", "USERID3", "CN=XXXX,OU=Users,OU=SITE3,OU=Italy,OU=LA,DC=XXXX,DC=XXXX"]]
Global $sTemp, $g_idListView, $g_bSortSense = False ; Set initial ascending sort
GUICreate("Active Directory Information", 420, 450)
$g_idListView = GUICtrlCreateListView("Name, First Name|UserID|Site|Country", 10, 10, 400, 430)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; Set background color of the listview for every second line
For $i = 1 To $aResult[0][0]
    $aTemp = StringSplit($aResult[$i][2], ",OU=", $STR_ENTIRESPLIT) ; split distinguishename
ConsoleWrite($i & @CRLF)
    $sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
    GUICtrlCreateListViewItem($sTemp, $g_idListview)
    GUICtrlSetBkColor(-1, 0xD0DEC7) ; Set background color of the listview for every second line
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Register handler
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Water, 

Here's the output:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\h74033\Downloads\GUICtrlCreateListView.au3"    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"C:\Users\h74033\Downloads\GUICtrlCreateListView.au3" (44) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & $aTemp[4]
$sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aTemp[3] & "|" & ^ ERROR
>Exit code: 1    Time: 2.001

If I comment 

& "|" & $aTemp[3] & "|" & $aTemp[4]

And let 

$sTemp = $aResult[$i][0] & "|" & $aResult[$i][1] ;& "|" & $aTemp[3] ;& "|" & $aTemp[4]

I got what I attached (sorry, had to hide the names). SITE and COUNTRY are missing though.

array.jpg

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • TheAutomator
      By TheAutomator
      Hi people,
      It's been a while
      I have been scripting in vbscript for some time but now i'm back using AutoIt for a project:
      Scripting Adobe Illustrator with AutoIt .
      This vb code needs to be converted:
      Set appRef = CreateObject("Illustrator.Application") 'Create a new document and assign it to a variable Set documentRef = appRef.Documents.Add 'Create a new text frame item and assign it to a variable Set sampleText = documentRef.TextFrames.Add 'Set the contents and position of the TextFrame sampleText.Position = Array(200, 200) sampleText.Contents = "Hello World!" The ... = Array(200,200) part is done in one line in vb, is this possible in AutoIt without declaring an array first?
      I know I sound like a newbie but I never had to use arrays this way before..
      what i have:
      $appRef = ObjCreate("Illustrator.Application") ;Create a new document and assign it to a variable $documentRef = $appRef.Documents.Add ;Create a new text frame item and assign it to a variable $sampleText = $documentRef.TextFrames.Add ;Set the contents and position of the TextFrame ReDim $sampleText.Position[2] = [200, 200] <<<--- doesn't work... $sampleText.Contents = "Hello World!"  
    • Dent
      By Dent
      I just can't get my head around what I'm trying to do.
      Ok so I read all the links in a webpage into a 1D array, I then make the array unique as there are some duplicates.
      I then find all the entries I want from the array and put the number of the row for those entries into another 1D array.
      So I now have two arrays; one has unique links, the other has the numbers of the rows for the links I actually want.
      Using the second array I would like to amend the first array, or create a third, with just the links I actually want.
      Confused? Welcome to my world.
      I'll put the relevant section of code below to show where I am up to.
      I've left the _ArrayDisplay in the above code which I am using to check the code does what I wanted. So the above code works fine, I'm just stumped on how to extract the links from $aLinks that I want.
      $oLinks = _IELinkGetCollection($oIE) Local $aLinks[1] = ["Link"] For $oLink in $oLinks _ArrayAdd($aLinks, $oLink.href) Next ;_ArrayDisplay($aLinks) $aLinks = _ArrayUnique($aLinks) ;_ArrayDisplay($aLinks) $aLinksToClick = _ArrayFindAll($aLinks, "azref", 0, 0, 0, 3) ;_ArrayDisplay($aLinksToClick) Local $aSortedLinks[1] = ["Sorted Links"] For $i = 0 To UBound($aLinksToClick) - 1 $Blah = _ArrayExtract($aLinks, $aLinksToClick[$i], $aLinksToClick[$i]) _ArrayAdd($aSortedLinks, $Blah) Next  
    • 31290
      By 31290
      Hi guys
      One of my project is to create an uninstaller GUI that list all app on a computer so  my techs can choose to remove apps without having to connect to his admin session (and loose time, especially while remotely controlling a domain machine).
      I did succeeded by creating a version one but it's very slow so I decided to create a version 2 of it, speeding things up and bring improvements.
      Here's my code so far:
      Problems are:
      1/ If I click 2 items, only the last one is taken into account when I click the "uninstall" button (the msgbox is for testing outputs ATM)
      2/ I can't figure out how to make the "Clear Selection" button to work (this may be a dumb question)
      3/ I'd like to queue un-installations according to what the tech checked, in your opinion, what is best? (Make the script generating and executing a sort of .bat file for each selection? / Make the script running "RunAsWait($sT0_AdminUserName, "DOMAIN" ,$sT0_AdminUserPassword, 2, "WMIC.exe product where ""name like '" & $sAppToUninstall& "'"" call uninstall /nointeractive","",@SW_HIDE) for each selection? /  write the selection in a .txt file and make the script read it line after line?, Other ideas? ^^)
      4/ How can I exclude some programs in the soft list? I mean, I don't want the tech to see all Security Update blablabla crap and other things in the list (as the Anti Virus..)
      Thanks a lot for those who can help, 
      Cheers,
      31290
    • Dent
      By Dent
      I've been searching for a solution on the forum and came across a partial solution in this topic...

      My problem is that I have a 2D array; column one has the description (a string) of the integer in column two. I want to sort this array by the value of column two from highest to lowest. Only my _ArraySort produces a strange result.
      Here is the code and the output before and after...
      Local $PensionsOne = ($MonthlyPensionIncomeOne + $MonthlyPensionCreditIncomeOne) Local $SecondEmploymentOne = ($SecondSalaryOne + $SecondBonusOne + $SecondOvertimeOne + $SecondCommissionOne) Local $aGetHighestFiveAdditionalIncomesForAppOne[8][2] = [ _ ["Occupational pension income", $PensionsOne], _ ["2nd job", $SecondEmploymentOne], _ ["Working Tax Credits", $MonthlyUniversalTaxCreditIncomeOne], _ ["Disability living allowance", $MonthlyStateDisabilityIncomeOne], _ ["Investment or dividend income", $MonthlyInvestmentIncomeOne], _ ["Maintenance", $MonthlyMaintenanceIncomeOne], _ ["Rental income", $MonthlyUnencumberedRentalIncomeOne], _ ["Self-employed income", $SecondNetPreTaxProfitLatestYrOne]] _ArrayDisplay($aGetHighestFiveAdditionalIncomesForAppOne) _ArraySort($aGetHighestFiveAdditionalIncomesForAppOne, 0, 0, 2) _ArrayDisplay($aGetHighestFiveAdditionalIncomesForAppOne)  


    • TheDcoder
      By TheDcoder
      Hello Guys! I wanted to share all my knowledge on arrays! Hope may enjoy the article , Lets start!
      Declaring arrays!
      Declaring arrays is a little different than other variables: 
      ; Rules to follow while declaring arrays: ; ; Rule #1: You must have a declarative keyword like Dim/Global/Local before the declaration unless the array is assigned a value from a functions return (Ex: StringSplit) ; Rule #2: You must declare the number of dimensions but not necessarily the size of the dimension if you are gonna assign the values at the time of declaration. #include <Array.au3> Local $aEmptyArray[0] ; Creates an Array with 0 elements (aka an Empty Array). Local $aArrayWithData[1] = ["Data"] _ArrayDisplay($aEmptyArray) _ArrayDisplay($aArrayWithData) That's it
      Resizing Arrays
      Its easy! Just like declaring an empty array! ReDim is our friend here:
      #include <Array.au3> Local $aArrayWithData[1] = ["Data1"] ReDim $aArrayWithData[2] ; Change the number of elements in the array, I have added an extra element! $aArrayWithData[1] = "Data2" _ArrayDisplay($aArrayWithData) Just make sure that you don't use ReDim too often (especially don't use it in loops!), it can slow down you program.
      Best practice of using "Enum"
      You might be wondering what they might be... Do you know the Const keyword which you use after Global/Local keyword? Global/Local are declarative keywords which are used to declare variables, of course, you would know that already by now , If you check the documentation for Global/Local there is a optional parameter called Const which willl allow you to "create a constant rather than a variable"... Enum is similar to Const, it declares Integers (ONLY Integers):
      Global Enum $ZERO, $ONE, $TWO, $THREE, $FOUR, $FIVE, $SIX, $SEVEN, $EIGHT, $NINE ; And so on... ; $ZERO will evaluate to 0 ; $ONE will evaluate to 1 ; You get the idea :P ; Enum is very useful to declare Constants each containing a number (starting from 0) This script will demonstrate the usefulness and neatness of Enums :
      ; We will create an array which will contain details of the OS Global Enum $ARCH, $TYPE, $LANG, $VERSION, $BUILD, $SERVICE_PACK Global $aOS[6] = [@OSArch, @OSType, @OSLang, @OSVersion, @OSBuild, @OSServicePack] ; Now, if you want to access anything related to the OS, you would do this: ConsoleWrite(@CRLF) ConsoleWrite('+>' & "Architecture: " & $aOS[$ARCH] & @CRLF) ConsoleWrite('+>' & "Type: " & $aOS[$TYPE] & @CRLF) ConsoleWrite('+>' & "Langauge: " & $aOS[$LANG] & @CRLF) ConsoleWrite('+>' & "Version: " & $aOS[$VERSION] & @CRLF) ConsoleWrite('+>' & "Build: " & $aOS[$BUILD] & @CRLF) ConsoleWrite('+>' & "Service Pack: " & $aOS[$SERVICE_PACK] & @CRLF) ConsoleWrite(@CRLF) ; Isn't it cool? XD You can use this in your UDF(s) or Program(s), it will look very neat!
      Looping through an Array
      Looping through an array is very easy! . There are 2 ways to loop an array in AutoIt!
      Simple Way:
      ; This is a very basic way to loop through an array ; In this way we use a For...In...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $vElement In $aArray ; $vElement will contain the value of the elements in the $aArray... one element at a time. ConsoleWrite($vElement & @CRLF) ; Prints the element out to the console Next ; And that's it! Advanced Way:
      ; This is an advanced way to loop through an array ; In this way we use a For...To...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $i = 0 To UBound($aArray) - 1 ; $i is automatically created and is set to zero, UBound($aArray) returns the no. of elements in the $aArray. ConsoleWrite($aArray[$i] & @CRLF) ; Prints the element out to the console. Next ; This is the advanced way, we use $i to access the elements! ; And that ends this section! For some reason, many people use the advance way more than the simple way .
      Interpreting Multi-Dimensional Arrays
      Yeah, its the most brain squeezing problem for newbies, Imagining an 3D Array... I will explain it in a very simple way for ya, so stop straining you brain now! . This way will work for any array regardless of its dimensions...
      Ok, Lets start... You can imagine an array as a (data) mine of information:

      ; Note that: ; Dimension = Level (except the ground level :P) ; Element in a Dimension = Path ; Level 2 ----------\ ; Level 1 -------\ | ; Level 0 ----\ | | ; v v v Local $aArray[2][2][2] ; \-----/ ; | ; v ; Ground Level ; As you can see that $aArray is the Ground Level ; All the elements start after the ground level, i.e from level 0 ; Level 0 Contains 2 different paths ; Level 1 Contains 4 different paths ; Level 2 Contains 8 different paths ; When you want too fill some data in the data mine, ; You can do that like this: $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 ; Don't get confused with the 0s & 1s, Its just tracing the path! ; Try to trace the path of a number with the help of the image! Its super easy! :D I hope you might have understand how an array looks, Mapping your way through is the key in Multi-Dimensional arrays, You take the help of notepad if you want! Don't be shy!
      Frequently Asked Questions (FAQs) & Their answers
      Q #1. What are Arrays?
      A. An Array is an datatype of an variable (AutoIt has many datatypes of variables like "strings", "integers" etc. Array is one of them). An Array can store information in a orderly manner. An Array consist of elements, each element can be considered as a variable (and yes, each element has its own datatype!). AutoIt can handle 16,777,216 elements in an Array, If you have an Array with 16,777,217 elements then AutoIt crashes.
      Q #2. Help! I get an error while declaring an Array!?
      A. You tried to declare an array like this:
      $aArray[1] = ["Data"] That is not the right way, Array is a special datatype, since its elements can be considered as individual variables you must have an declarative keyword like Dim/Global/Local before the declaration, So this would work:
      Local $aArray[1] = ["Data"] Q #3. How can I calculate the no. of elements in an array?
      A. The UBound function is your answer, Its what exactly does! If you have an multi-dimensional Array you can calculate the total no. of elements in that dimension by specifying the dimension in the second parameter of UBound
      Q #4. Why is my For...Next loop throwing an error while processing an Array?
      A.  You might have done something like this:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) ; Concentrate here! $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Did you notice the mistake? UBound returns the no. of elements in an array with the index starting from 1! That's right, you need to remove 1 from the total no. of elements in order to process the array because the index of an array starts with 0! So append a simple - 1 to the statment:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) - 1 $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Q #5. Can an Array contain an Array? How do I access an Array within an Array?
      A. Yes! It is possible that an Array can contain another Array! Here is an example of an Array within an Array:
      ; An Array can contain another Array in one of its elements ; Let me show you an example of what I mean ;) #include <Array.au3> Global $aArray[2] $aArray[0] = "Foo" Global $aChildArray[1] = ["Bar"] $aArray[1] = $aChildArray _ArrayDisplay($aArray) ; Did you see that!? The 2nd element is an {Array} :O ; But how do we access it??? ; You almost guessed it, like this: ; Just envolope the element which contains the {Array} (as shown in _ArrayDisplay) with brackets (or parentheses)! :D ConsoleWrite(($aArray[1])[0]) ; NOTE the brackets () around $aArray[1]!!! They are required or you would get an syntax error! ; So this: $aArray[1][0] wont work!  
      More FAQs coming soon!