Jump to content
31290

playing with arrays and lists

Recommended Posts

31290

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
31290

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
31290

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
water

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 (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
31290

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
water

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 (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

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 (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
31290

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
water

Sure. Remove line

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

and the comments in the 3 lines above.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
31290

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
water

_AD_Open is missing at the top of your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
31290

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
water

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 (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
31290

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
water

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
31290

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
water

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 (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
31290

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

    • jasty
      By jasty
      In every other language doing   
      dim $a[3] = [1, 2, 3] $b = $a creates a reference to a but in autoit it always makes a copy.  I didn't realize this until I have performance problems and now I'm trying to switch over to the reference behavior.  How can I change the above statement so b is a reference to a and not a full copy? 
    • rm4453
      By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
    • AnonymousX
      By AnonymousX
      Hello,
      So this may be more of a challenge of effective programming then specific to AutoIT but I want to solve this problem with AutoIT  so i'm putting it here. (If someone has a better language to solve with I'm all ears)
       
      So the task I'm trying to achieve is that I have multiple .CSV files that have: year, month, day, hour, value. I need to be able to sum up all the values that have the same date/time, then find which date and time has the maximum value.
       
      The problem is that each file may or may not have same amount of days/hours as the rest. So I need to devise a way to handle this. 
       
      Example:
      File A   File B   File C 2018 1 1  1:00 10   2018 1 1 2:00 10   2018 1 1  1:00 10 2018 1 1  2:00 12   2018 1 1 3:00 12   2018 1 2 1:00 12 2018 1 1  3:00 14   2018 1 1 4:00 14   2018 2 1  1:00 16 2018 2 1  1:00 16   2018 2 1  1:00 16              
       Answer I want to be spit out is Feb 1st 2018 at 2:00 with value of 48
       
      So far I've got code to store all .CSV files to an array, then a loop to go through each csv, but not sure how to effectively manipulate the data. Keep in mind each file has over 7000 time entry points.
       
      If anyone can solve this that would be pretty awesome! 
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> RefineData() Func RefineData() Local $i, $filenum, $file, $csvArray, $FilePath = @ScriptDir $fileList = _FileListToArrayRec($FilePath, "*.csv", 1) ;Create and array of all .csv files within folder Local $chkArray[UBound($fileList)][2] ;=====Loop through the .csv files within the folder====== For $filenum = 1 To UBound($fileList) - 1 Step 1 $file = $fileList[$filenum] $sFilePath = $FilePath & "\" & $file ;=====Create array based on csv file===== _FileReadToArray($sFilePath, $csvArray, $FRTA_NOCOUNT, ",") ;#### Operations here ###### next msgbox(0,"", "Date: " & $date_of_max & "Value: " & $maxVal );display solution endfunc  
    • corz
      By corz
      Associative Array Functions
      I've seen a couple of UDFs for this on the forum. One of them I quite like. But it's still nearly not as good as this method, IMHO.
      I don't recall if I discovered the "Scripting.Dictionary" COM object myself or if I got the original base code from somewhere online. I have recently searched the web (and here) hard for any AutoIt references to this, other than my own over the years I've been using this (in ffe, etc..), and I can find nothing, so I dunno. If anyone does, I'd love to give credit where it's due; this is some cute stuff! It could actually be all my own work! lol
      At any rate, it's too useful to not have posted somewhere at autoitscript.com, so I've put together a wee demo.
      For those who haven't heard of the COM "Scripting.Dictionary".. 
      If you've ever coded in Perl or PHP (and many other languages), you know how useful associative arrays are. Basically, rather than having to iterate through an array to discover it's values, with an associative array you simply pluck values out by their key "names".
      I've added a few functions over the years, tweaked and tuned, and this now represent pretty much everything you need to easily work with associative arrays in AutoIt. En-joy!
      The main selling point of this approach is its simplicity and weight. I mean, look at how much code it takes to work with associative arrays! The demo is bigger than all the functions put together! The other selling point is that we are using Windows' built-in COM object functions which are at least theoretically, fast and robust.
      I've used it many times without issues, anyhow, here goes..
      ; Associative arrays in AutoIt? Hells yeah! ; Initialize your array ... global $oMyError = ObjEvent("AutoIt.Error", "AAError") ; Initialize a COM error handler ; first example, simple. global $simple AAInit($simple) AAAdd($simple, "John", "Baptist") AAAdd($simple, "Mary", "Lady Of The Night") AAAdd($simple, "Trump", "Silly Man-Child") AAList($simple) debug("It is said that Trump is a " & AAGetItem($simple, "Trump") & ".", @ScriptLineNumber);debug debug("") ; slightly more interesting.. $ini_path = "AA_Test.ini" ; Put this prefs section in your ini file.. ; [test] ; foo=foo value ; foo2=foo2 value ; bar=bar value ; bar2=bar2 value global $associative_array AAInit($associative_array) ; We are going to convert this 2D array into a cute associative array where we ; can access the values by simply using their respective key names.. $test_array = IniReadSection($ini_path, "test") for $z = 1 to 2 ; do it twice, to show that the items are *really* there! for $i = 1 to $test_array[0][0] $key_name = $test_array[$i][0] debug("Adding '" & $key_name & "'..");debug ; key already exists in "$associative_array", use the pre-determined value.. if AAExists($associative_array, $key_name) then $this_value = AAGetItem($associative_array, $key_name) debug("key_name ALREADY EXISTS! : =>" & $key_name & "<=" , @ScriptLineNumber);debug else $this_value = $test_array[$i][1] ; store left=right value pair in AA if $this_value then AAAdd($associative_array, $key_name, $this_value) endif endif next next debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) debug(@CRLF & "Removing 'foo'..");debug AARemove($associative_array, "foo") debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) debug(@CRLF & "Removing 'bar'..");debug AARemove($associative_array, "bar") debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) quit() func quit() AAWipe($associative_array) AAWipe($simple) endfunc ;; Begin AA Functions func AAInit(ByRef $dict_obj) $dict_obj = ObjCreate("Scripting.Dictionary") endfunc ; Adds a key and item pair to a Dictionary object.. func AAAdd(ByRef $dict_obj, $key, $val) $dict_obj.Add($key, $val) If @error Then return SetError(1, 1, -1) endfunc ; Removes a key and item pair from a Dictionary object.. func AARemove(ByRef $dict_obj, $key) $dict_obj.Remove($key) If @error Then return SetError(1, 1, -1) endfunc ; Returns true if a specified key exists in the associative array, false if not.. func AAExists(ByRef $dict_obj, $key) return $dict_obj.Exists($key) endfunc ; Returns a value for a specified key name in the associative array.. func AAGetItem(ByRef $dict_obj, $key) return $dict_obj.Item($key) endfunc ; Returns the total number of keys in the array.. func AACount(ByRef $dict_obj) return $dict_obj.Count endfunc ; List all the "Key" > "Item" pairs in the array.. func AAList(ByRef $dict_obj) debug("AAList: =>", @ScriptLineNumber);debug local $k = $dict_obj.Keys ; Get the keys ; local $a = $dict_obj.Items ; Get the items for $i = 0 to AACount($dict_obj) -1 ; Iterate the array debug($k[$i] & " ==> " & AAGetItem($dict_obj, $k[$i])) next endfunc ; Wipe the array, obviously. func AAWipe(ByRef $dict_obj) $dict_obj.RemoveAll() endfunc ; Oh oh! func AAError() Local $err = $oMyError.number If $err = 0 Then $err = -1 SetError($err) ; to check for after this function returns endfunc ;; End AA Functions. ; debug() (trimmed-down version) ; ; provides quick debug report in your console.. func debug($d_string, $ln=false) local $pre ; For Jump-to-Line in Notepad++ if $ln then $pre = "(" & $ln & ") " & @Tab ConsoleWrite($pre & $d_string & @CRLF) endfunc  
      ;o) Cor
    • Ambient
      By Ambient
      I am trying to build a list from a query run against a sybase db. This part works fine. My problem is this, I want to display values in a list depending 
      on the value of certain fields  i.e. See below which works for two. Unfortunately, I need it to work for 3 values.  I don't know how I can do this for 3.  I did try doing a select case but I was getting errors.
       
      i.e. if value =0  then "Card Check" if Value = - Then "Card Spend" Else "Money Added"
      The below immediate iif works brilliantly for two but as I say I need to build this with 3 different values. 
       
       
      $idItem = GUICtrlCreateListViewItem( _iif($adoRs.Fields("TransactionAmount").value =0, "Card check","Money Added") 
       
      Any help appreciated.
×