amphoric

Array in to List View and Updated after Loop

4 posts in this topic

#1 ·  Posted

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

#2 ·  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.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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

#3 ·  Posted

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

#4 ·  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.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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

    • Ascer
      By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1+ System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
    • FMS
      By FMS
      Hello,
      I'm trying to read a binary file to an array but couln't get it to work.
      Also I coul not find any help in the forum around this subject whish was helpfull.
      Is there any way it could be done?
      I tried a lot of ways but maybe somebody know's the right way?
      #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> Local $in=FileOpen("TEST_labels.idx1-ubyte",16) ; 16+0=Read binary Local $data = FileRead($in) Local $FileArray = BinaryToString($data,4) ;~ $FileArray = StringSplit($BinarydData, @CRLF, 1+2) ;~ Local $FileArray = StringRegExp($BinarydData, "[^\r\n]+", 3) FileClose($in) _ArrayDisplay($FileArray,"$FileArray","",32) MsgBox($MB_SYSTEMMODAL, "", "$FileArray = " & $FileArray )  
      TEST_labels.idx1-ubyte
    • Anas
      By Anas
      Hi,

      Is it possible to set a different text direction/layout (not alignment) for a Listview column?
       
      Thanks.
    • ur
      By ur
      I am reading a CSV file which is tab seperated as below.
      Local $aArray = FileReadToArray($file) And now, I am splitting this main array record wise so that Array contains internally another arrow to represent each row.
      For $i = 0 to (UBound($aArray) - 1) ;MsgBox(0,"",$aArray[$i]) $aArray[$i] = StringSplit(StringStripCR($aArray[$i]), Chr(9),2);Chr(9) for tab ;_ArrayDisplay($aArray[$i]) Next Afther that, _ArrayDIsplay is able to see the individual internal arrays.
      _ArrayDisplay($aArray[1]) But If I try to access the individual element of it as below.It is not showing any result.
      MsgBox(0,"",$aArray[1][1]) Any suggestion, below is the sample csv file.
      New Text Document.csv
    • Jibsbrown
      By Jibsbrown
      So trying to get an INI section in a listView with checkboxes. Was able to get the the section values to show until i add the checkboxes and now only the keys are show up. Between reading the Help file, Forum Topic and trying other code option. I have been unable to answer this problem. I'm assuming its something very basic I'm overlooking since this it's day 21 of learning Autoit.
      If someone could please advise I would appreciate the assistance.
       
      Here's the code: 
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GUIListView.au3> #include <Array.au3> #include <File.au3> #include <ListViewConstants.au3> Global $sIniPath = "installLog.ini" ;ConsoleWrite($sIniPath) $iniSctionNames = IniReadSectionNames($sIniPath) ;_ArrayDisplay($iniSctionNames, "$iniSctionNames") $keys2 = IniReadSection($sIniPath, $iniSctionNames[2]) _ArrayDisplay($keys2 , "$keys2") ; Create GUI $hGUI = GUICreate("Test", 300, 250) ; Create ListView $cLV = GUICtrlCreateListView("", 10, 10, 200, 200,$LVS_List,$LVS_EX_CHECKBOXES) _GUICtrlListView_AddColumn($cLV, $keys2, 100) _GUICtrlListView_AddColumn($cLV, $keys2, 100) ;_GUICtrlListView_AddItem($cLV, $keys2, 0) _GUICtrlListView_AddArray($cLV, $keys2) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd And the INI file I'm using. 
      [OldSysInfo] 4=192.168.0.4|DESKTOP-RDIU2SN|R90M05Q8 5=192.168.0.5|SD0123456789101|R9WGP9P 6=192.168.0.6|SD0123456789102|R9WGP9PT 3=192.168.0.3|DESKTOP-3RS4LKL|R9WGP9P 23=192.168.0.23|SD0123456789102|MXL1234P5I [PrinterIp] 50=192.168.0.50 48=192.168.0.48 47=192.168.0.47 [NewSysInfo] newPC = SD0123456789adfs|192.168.0.185|2UA1234FTR Also if possible could you explain how to hide the Array count row as well.