amphoric Posted January 9, 2018 Posted January 9, 2018 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 expandcollapse popup#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
careca Posted January 9, 2018 Posted January 9, 2018 (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 January 9, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders 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. 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
amphoric Posted January 9, 2018 Author Posted January 9, 2018 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
careca Posted January 9, 2018 Posted January 9, 2018 (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 January 9, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders 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. 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now