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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.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
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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

    • NiftRex
      By NiftRex
      I'm trying to get an array from a website so that I can just get the url, but I am not sure how. I read a bit of arrays but I have a feeling I'd have to be writing a lot more than what I should be. I will include the script I have so far and the API url for what I want.
       
      API: https://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1 (I want the 'url' array that contains the url)
       
      Code:
      #include <MsgBoxConstants.au3> #include <Inet.au3> #include <Array.au3> $site = _INetGetSource('http://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1') MsgBox($MB_SYSTEMMODAL, "Title", $site[1])  
    • rcmaehl
      By rcmaehl
      Alright, currently I'm trying to merge two loops:
       
      Local $aArray[99][13] For $iLoop = 1 to 100 $aArray[$iLoop - 1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop) If @error <> 0 Then ReDim $aArray[$iLoop - 1][13] ExitLoop EndIf Next For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 1 to 12 $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop Next Next  
      into one. Here's what I have so far:
       
      Local $aArray[99][13] For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 0 to 12 ConsoleWrite("Loop1 = " & $iLoop1 & ", Loop2 = " & $iLoop2 & @CRLF) If $iLoop2 = 0 Then $aArray[$iLoop1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop1 + 1) If @error <> 0 Then ReDim $aArray[$iLoop1 + 1][13] ExitLoop EndIf Else $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop EndIf Next Next And it keeps error-ing out trying to exceed the dimension range of the array. Does the Loop not recheck the size of the array after the original check or am I doing something else wrong.
       
      Thanks.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly...
      What I'd like to do is retrieve data from 2 tables and display in a listview...
      I tried with:
      Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database...
      What do you need to help me?
      Thanks  

      EDIT:
      Managed with a double If and double query like this:
       
      $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created
      If anyone has another more efficient way, I'm here Thanks guys  
       
    • 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