Jump to content
amphoric

Array in to List View and Updated after Loop

Recommended Posts

amphoric

Hi,

I am struggling converting my 1D array to a 2D array and then showing that in my List View. Below is my current code, where I would like to take the array from the input box, and have that displayed as a list within the list view this is a list of computer names, and then update the 2nd column of each line once I have ran a ping and a registry change on each computer name, with either 'Completed' and 'Failed'

I have checked out the AutoIt Arrays page here: https://www.autoitscript.com/wiki/Arrays , but unfortunately I cannot get my head around it. Any help would be greatly appreciated.

I hope this makes sense.

Thanks

 

#include <Date.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>


#Region ###
$Form1 = GUICreate("Title", 515, 533, -1, -1)
GUISetBkColor(0xFFFFFF)
$Pic2 = GUICtrlCreatePic("Images\pic.jpg", 16, 16, 212, 28)
$Label1 = GUICtrlCreateLabel("Label", 240, 16, 271, 33, $SS_CENTER)
GUICtrlSetFont(-1, 17, 800, 0, "")
$Combo1 = GUICtrlCreateCombo("", 256, 406, 241, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))
$Label2 = GUICtrlCreateLabel("Please select the location", 45, 401, 210, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "")
$ChangeButton = GUICtrlCreateButton("Change", 286, 487, 75, 25)
$RePromptButton = GUICtrlCreateButton("Re-prompt User", 366, 487, 139, 25)
$Checkbox1 = GUICtrlCreateCheckbox("I have ensured that my selection is correct.", 10, 487, 273, 25)
GUICtrlSetFont(-1, 10, 400, 0, "")
$ManLocation = GUICtrlCreateLabel("Please enter the location:", 59, 448, 189, 20, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 800, 0, "")
GUICtrlSetState(-1, $GUI_HIDE)
$ManLocInput = GUICtrlCreateInput("", 256, 445, 241, 24)
GUICtrlSetState(-1, $GUI_HIDE)
$Label5 = GUICtrlCreateLabel("for this device:", 138, 418, 109, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "")
$Label3 = GUICtrlCreateLabel("Asset Number:", 98, 72, 107, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "")
$Input1 = GUICtrlCreateInput("", 215, 69, 241, 24)
$AddMulti = GUICtrlCreateLabel("Add Multiple Assets", 356, 55, 98, 13, $SS_RIGHT)
GUICtrlSetFont(-1, 8, 400, 6, "")
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetCursor (-1, 0)
$List1 = GUICtrlCreateListView("", 16, 104, 481, 278)

$Add = GUICtrlCreateButton("Add", 461, 68, 35, 25)
GUISetState(@SW_SHOW)
#EndRegion ### 



;### StartForm ###
    $FormaMultiple = GUICreate("Title", 277, 418, -1, -1)
    GUISetBkColor(0xFFFFFF)
    $Label1 = GUICtrlCreateLabel("Please add 1 asset number per line.", 8, 11, 253, 20, $SS_CENTER)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $OK = GUICtrlCreateButton("OK", 56, 375, 75, 25)
    $Edit1 = GUICtrlCreateEdit("", 20, 40, 233, 329)
    $Cancel = GUICtrlCreateButton("Cancel", 136, 375, 75, 25)
    GUISetState(@SW_HIDE)
;### EndForm ###



;### Add List View Columns START ###

;### Add List View Columns END ###




;### Read Locations START ###
    ;Read the LOCAL ini file SECTIONS
    Global $aSections = IniReadSectionNames("Locations.ini")

    ;If the above succeeded, convert the array to a string with each item separated by a | (pipe) and set the default selected item to $aSections[1]
    If(Not @Error) Then GUICtrlSetData($Combo1, _ArraytoString($aSections, "|", 1), $aSections[1])
;### Read Locations END ###



;### Require Admin START ###
    ;#RequireAdmin
;### Require Admin END ###



While 1
    $nMsg = GUIGetMsg()


;### Data Validation START ###
    ;Set Checkbox = ENABLE/DISABLE
    if not GUICtrlRead($Combo1) = "" AND GUICtrlRead($Combo1) = "Not In List" then
        if not GUICtrlRead($ManLocInput) = "" Then
            If not ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_ENABLE)
        Else
            If ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_DISABLE)
        EndIf
    Else
        if GUICtrlRead($Combo1) = "" Then
            If ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_DISABLE)
        Else
            If not ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_ENABLE)
        EndIf
    EndIf

    ;Set Button = ENABLE/DISABLE
    If GUICtrlRead($Checkbox1) = 1 Then
        If Not ControlCommand($Form1, "", $ChangeButton, "IsEnabled") Then GUICtrlSetState($ChangeButton, $GUI_ENABLE)
    Else
        If ControlCommand($Form1, "", $ChangeButton, "IsEnabled") Then GUICtrlSetState($ChangeButton, $GUI_DISABLE)
    EndIf
;### Data Validation END ###



    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit



        case $Add








        Case $AddMulti
            GUISetState(@SW_SHOW, $FormaMultiple)

        Case $Cancel
            GUISetState(@SW_HIDE, $FormaMultiple)
        Case $OK
            $sText = GUICtrlRead($Edit1)
            $aText = StringSplit($sText, @CRLF, 1)
            $bText = _ArrayToString($aText, ";", 1, -1)
            $cText = StringStripWS($bText, $STR_STRIPALL )
            $dText = StringReplace($cText,";;",";")
            GUICtrlSetData($Input1, $dText)
            GUICtrlSetData($Edit1, "")
            GUISetState(@SW_HIDE, $FormaMultiple)
            For $i = 1 To $aText[0]
            Next

        Case $Combo1 ; If the combo is actioned
            Switch GUICtrlRead($Combo1)
                Case "Not In List" ; Show the manual input controls
                    GUICtrlSetState($ManLocation, $GUI_SHOW)
                    GUICtrlSetState($ManLocInput, $GUI_SHOW)
                    if ControlCommand($Form1, "", $Checkbox1, "IsChecked") then ControlCommand($Form1, "", $Checkbox1, "Uncheck")
                    GUICtrlSetData($ManLocInput, "")

                Case Else ; Hide them
                    GUICtrlSetState($ManLocation, $GUI_HIDE)
                    GUICtrlSetState($ManLocInput, $GUI_HIDE)
                    if ControlCommand($Form1, "", $Checkbox1, "IsChecked") then ControlCommand($Form1, "", $Checkbox1, "Uncheck")
                    GUICtrlSetData($ManLocInput, "")

            EndSwitch

        Case $ChangeButton
            ChangeReg()

        Case $RePromptButton
            RemoveReg()
    EndSwitch
WEnd

Func ChangeReg()

            $MultiAssets = StringSplit(GUICtrlRead($Input1), ";", 1)
            For $i = 1 To $MultiAssets[0]



    ; Ping with a timeout of 250ms.
    Local $iPing = Ping($MultiAssets[$i], 250)

    If $iPing Then ; If a value greater than 0 was returned then do the following:

        if not GUICtrlRead($ManLocInput) = "" Then

            RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "# - " & GUICtrlRead($ManLocInput))
            RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "# - " & GUICtrlRead($ManLocInput))
            RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC)
            RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC)
            MsgBox($MB_SYSTEMMODAL, "Completed", "Completed")

        Else
            If not GUICtrlRead($Input1) = "" Then

                RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", GUICtrlRead($Combo1))
                RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", GUICtrlRead($Combo1))
                RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC)
                RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC)
                MsgBox($MB_SYSTEMMODAL, "Completed", $MultiAssets[$i] & @CRLF & " Changed to: " & GUICtrlRead($Combo1))
            Else
                MsgBox($MB_SYSTEMMODAL, "Error", "Please ensure all boxes are completed")
            EndIf
        EndIf

    Else

        MsgBox($MB_SYSTEMMODAL, "Error", "This asset may be OFFLINE, unable to complete")
    EndIf
            Next
EndFunc   ;==>PingReg


Func RemoveReg()

    $MultiAssets = StringSplit(GUICtrlRead($Input1), ";", 1)
            For $i = 1 To $MultiAssets[0]




    ; Ping with a timeout of 250ms.
    Local $iPing = Ping($MultiAssets[$i], 250)

    If $iPing Then ; If a value greater than 0 was returned then do the following:

        if not GUICtrlRead($ManLocInput) = "" Then

            RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "")
            RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "")
            RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", "")
            RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", "")
            MsgBox($MB_SYSTEMMODAL, "Completed", "Completed")

        Else
            If not GUICtrlRead($Input1) = "" Then

                RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "")
                RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "")
                RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", "")
                RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", "")
                MsgBox($MB_SYSTEMMODAL, "Completed", $MultiAssets[$i] & @CRLF & "CLEARED")
            Else
                MsgBox($MB_SYSTEMMODAL, "Error", "Please ensure all boxes are completed")
            EndIf
        EndIf




    Else

        MsgBox($MB_SYSTEMMODAL, "Error", "This asset may be OFFLINE, unable to complete")
    EndIf
Next
EndFunc   ;==>PingReg1

 

Share this post


Link to post
Share on other sites
careca
Posted (edited)
$List1 = GUICtrlCreateListView("1|2", 16, 104, 481, 278)

that gives the listview 2 columns.

now you just write to one or the other

I'd suggest that you could write the computer list into the first column, and then ping the items in the column, writing the result to the second column.

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
amphoric

Thanks Careca!

I now have the columns working a treat, although how would I write to the second column the results? I loop through each computer 1 at a time?

 

Thanks

Share this post


Link to post
Share on other sites
careca
Posted (edited)

help file says it all about how.

Run through each item, and ping, write the result to the second column, come back with what you tried that didnt work.

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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

    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
    • Zein
      By Zein
      #include "..\Include\Array.au3" #include "..\Include\File.au3" #include "..\Include\AutoItConstants.au3" Local $aRetArray Local $sFilePath = "n.csv" _FileReadToArray($sFilePath, $aRetArray, ",") ; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",") _ArrayDisplay($aRetArray, "Original", Default, 8) The above code shows two versions of _FileReadToArray and both don't work as expected.
      The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

      I looked again at the documentation:
       
      #include <File.au3> _FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )
      And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
      I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

       
    • ternal
      By ternal
      Hi,
      Recently I have had the need to do a sort and then do a second sort while the item of the first sort stays the same ( double sorting , first on column x then while column x is the same sort column y).
      I did not put much efffort into error checking but so far I did not need it.
      For my applications so far it works perfectly however if someone is willing I want to test this extensivly.
      If anyone has big lists of random stuff to sort could you try this out please?
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArraySort_Double ; Description ...: ; Syntax ........: _ArraySort_Double (Byref $array[, $first_index = Default[, $second_index = Default[, $ascending = Default]]]) ; Parameters ....: $array - 2d array to sort. ; $first_index - [optional] first column to sort. Default is 0. ; $second_index - [optional] second column to sort. Default is 1. ; $ascending - [optional] ascending/descending. Default is 1. ; Return values .: 1 if no errors occured , -1 if errors occured ; Author ........: Ternal ; Remarks .......: Needs excessive testing. ; Related .......: _arraysort() ; =============================================================================================================================== Func _ArraySort_Double (byref $array, $first_index = Default, $second_index = Default, $ascending = Default) Local $temp_value Local $counter = 1 If UBound($array, $UBOUND_DIMENSIONS) <> 2 Then MsgBox(0, "error", "error") return -1 EndIf If $first_index = Default Then $first_index = 0 If $second_index = Default Then $second_index = 1 If $ascending = Default Then $ascending = 1 _ArraySort($array, $ascending, 0, 0, $first_index); you can alter settings of primary sort here If @error Then MsgBox(0, "error", @error) return -1 EndIf $temp_value = $array[0][$first_index] For $x = 1 to UBound($array, 1) - 1 If Mod( $x, 10000) = 0 Then ConsoleWrite("at " & $x & " of a total : " & UBound($array, 1) & @CRLF) If $array[$x][$first_index] = $temp_value Then $counter+= 1 If $x = UBound($array, 1) - 1 Then; do last line here(if last line is not a new item) _ArraySort($array, $ascending, $x - $counter, $x, $second_index);you can alter settings of secondary sort here(don't forget to place line 34 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf EndIf Else If $counter > 0 Then ;at least 2 of the same _ArraySort($array, $ascending, $x - $counter, $x - 1, $second_index);you can alter settings of secondary sort here(don't forget to place line 29 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf $counter = 1 EndIf EndIf $temp_value = $array[$x][$first_index] Next Return 1 EndFunc Kind regards, Ternal
    • TrashBoat
      By TrashBoat
      So I've made this script that detects how long i have held down my left mouse button for and stores the information in an array and then sorts its using _ArraySort but the output is half sorted half broken.
      Here's my script:
      HotKeySet("{F1}","_exit") #include <Misc.au3> #include <Timers.au3> #include <Array.au3> Local $dll = DllOpen("user32.dll") $on = False Global $array[0] While(1) If _IsPressed(01,$dll) Then $timer = _Timer_Init() While _IsPressed(01,$dll) Sleep(1) WEnd $time = _Timer_Diff($timer) _ArrayAdd($array,"Time: " & Floor($time) & " ms") ;~ ConsoleWrite("Time: " & Floor($time) & " ms" & @CRLF) EndIf Sleep(50) WEnd Func _exit() _ArraySort($array) _ArrayDisplay($array) Exit EndFunc And the output:

      See how its not sorted?  What is the problem here?
    • MrCheese
      By MrCheese
      Hi guys,
      See attached for an array example.
      to simplify what i want to achieve,  I want to split this array into 9 different csv files.
      the first file would contain the list of "key" and the corresponding "ID1", the second would have "key" and the "ID2", the third would have "key" and "ID3"
      However, I want to remove all the rows that don't have an ID recorded in the respective ID2, ID3 4...5...6 etc, so the file only contains row items with a key and the ID.
      Would be the best way to loop through the rows and delete the row if the array field is blank - would I then need to repeat that row ID to check that the row that its replaced is also empty (ie the one after the one I just deleted)? I see this getting messy.
      or _arraySort, and delete everything below the last filled row? <-- this might be best?
      Or should I use the excel UDF, apply a filter (not selecting the blanks), then create/export to the array->csv?
       
      Super keen to hear your thoughts.
      thanks!
       
       
       
       
      IDArray.csv
×