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.

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.

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.

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.

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

    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
×