Jump to content

Array to create label & array to highlight label with icon on success or fail


goss34
 Share

Go to solution Solved by JohnOne,

Recommended Posts

Hi Guys,

I hope that title makes some sense if not hopefully the code below will. Essentially i am trying to create a basic monitor (basic may turn to complex as my confidence grows), the script should work as below:

Start ConfigGUI

On close start MonitorGUI

MonitorGUI should read a file, create an array and show a label for each entry in the array

A loop should run which will ping each member of the array

If successful a green icon should appear next to the appropriate label

if unsuccessful a red icon should appear next to the appropriate label

I do not know how to get the green icon to match up with the appropriate label but i think the underlying functionality is working because as it works through the list the notification changes from green to red and vice versa.

Below is my full code, it should hopefully work on any system (hopefully) if you place extract the zip file to "C:" on your PC first.

#include <Inet.au3>
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <GuiListView.au3>

;Disable tray icon pause
AutoItSetOption("TrayAutoPause",0)

;Create installation directory
DirCreate(@TempDir & "\Uptime_Monitor")

;Setup help function
FileInstall("C:\Uptime_Monitor_Help.chm", @TempDir & "\Uptime_Monitor\Uptime_Monitor_Help.chm", 1)
HotKeySet("^{F1}", "ShowMessage")
TrayTip("", "CTRL+F1 For Help!", 15)

;Setup Gui icons
FileInstall("C:\green.ico", @TempDir & "\Uptime_Monitor\green.ico", 1)
FileInstall("C:\red.ico", @TempDir & "\Uptime_Monitor\red.ico", 1)
Global $green = (@TempDir & "\Uptime_Monitor\green.ico")
Global $red = (@TempDir & "\Uptime_Monitor\red.ico")

;Setup sound clips
FileInstall("C:\ErrorMsg.mp3", @TempDir & "\Uptime_Monitor\ErrorMsg.mp3", 1)
Global $ErrSound = (@TempDir & "\Uptime_Monitor\ErrorMsg.mp3")

;Create default configuration files
$sFilePath = (@TempDir & "\Uptime_Monitor\Monitor.txt") ; Set Path Directory
If Not FileExists($sFilePath) Then
    _FileCreate($sFilePath) ; if file does not exist create file
    MsgBox(0, "Created", "Yes") ; confirmation file was created
    $file = FileOpen($sFilePath, 1) ; open file for editing

    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
    Else
        FileWrite($file, "Server1.domain.local" & @CRLF) ; write 1 line to file
        FileWrite($file, "Server2.domain.local" & @CRLF) ; write additional line to file
        FileWrite($file, "Server3.domain.local") ; write additional line to file
        FileClose($file) ; close open file
    EndIf
    Else
EndIf

If Not FileExists(@TempDir & "\Uptime_Monitor\Log.txt") Then
    _FileCreate(@TempDir & "\Uptime_Monitor\Log.txt")
EndIf

;Set additional global variables
Global $sort = False

;######################;
;;;;;;;Functions;;;;;;;;
;######################;

;Help function
Func ShowMessage()
    ShellExecute(@TempDir & "\Uptime_Monitor\Uptime_Monitor_Help.chm")
EndFunc


;Launch ConfigGUI function
ConfigGUI()

;ConfigGUI funtction
Func ConfigGui()
    ; Read the current script file into an array using the filepath.
    Local $aArray = FileReadToArray($sFilePath)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
    EndIf

    ; start gui code
    local $gui = guicreate('Initial Configuration',320,200)
    local $lv  = GUICtrlCreateListView('Monitored Servers',10,40,210,150) ;,$LVS_REPORT)
    ;local $getserverbtn  = GUICtrlCreatebutton('Get Server',180,50,80,20)
    local $addbtn = GUICtrlCreateButton("Add", 230, 10, 80, 20)
    local $removebtn = GUICtrlCreateButton("Remove", 230, 40, 80, 20)
    local $Input = GUICtrlCreateInput("Type server name to add...", 10,10,210,20)

    ; this routine reads the array created above and populates the listview
    for $1 = 0 to UBound($aArray) - 1
        GUICtrlCreateListViewItem($aArray[$1],$lv)
        ConsoleWrite($aArray[$1] & @CRLF) ; added just so i can see the data received into the array
        _GUICtrlListView_SetColumnWidth ($LV, 0, $LVSCW_AUTOSIZE)
        _GUICtrlListView_SimpleSort($LV, $Sort, 0, False)

    next

    guisetstate()

    while 1
        switch guigetmsg()
            case $GUI_EVENT_CLOSE
                guidelete($gui)
                ExitLoop
            case $addbtn
                $file = FileOpen($sFilePath, 1) ; open file for editing
                ;FileWrite($file, @CRLF)
                FileWrite($file, GUICtrlRead($Input) & @CRLF) ; write entry from input box into file
                FileClose($file) ; close open file
                GUICtrlCreateListViewItem(guictrlread($input),$lv)
                _GUICtrlListView_SimpleSort($LV, $Sort, 0, False)
            case $removebtn
                ;MsgBox(0,"Remove", "Remove button pushed", 0)
                    Global $success = False
                    $file_name = $sFilePath
                    $line_text_input = (StringTrimRight( _
                                            guictrlread( _          ; get control id of selected item
                                            guictrlread($lv)), _
                                            1) )                    ; get listview item text using the control id
                    $file_count_lines = _FileCountLines($file_name)
                    for $i = 0 to $file_count_lines
                        $Lines_text_output = FileReadLine($file_name, $i)
                        if StringInStr($Lines_text_output, $line_text_input) then
                            _FileWriteToLine($file_name, $i, "", 1)
                            $success = True
                            ExitLoop
                        EndIf
                    _GUICtrlListView_DeleteItemsSelected($lv)
                    Next
                    if $success = True Then
                        MsgBox(0, "Success", "Server has been deleted")
                    Else
                        MsgBox(0, "Failure", "Server wasn't found - Case Sensitive")
                    EndIf
        EndSwitch
    wend
EndFunc


;Launch MonitorGUI function
MonitorGUI()

;MonitorGUI funtction
Func MonitorGUI()

    Global $iW = 320, $iH = 180, $iT = 52, $iB = 52, $iLeftWidth = 150, $iGap = 10, $hMainGUI
    Local $sMainGuiTitle = "System Monitor"
    Local $sFooter = "2015 © MonitorGUI"
    Local $aArray = FileReadToArray($sFilePath)
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
        Else

            $hMainGUI = GUICreate($sMainGuiTitle, $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
            GUISetIcon($green, $hMainGUI)
            GUICtrlCreateLabel($sFooter, 10, $iH - 34, $iW - 20, 17, BitOR($SS_LEFT, $SS_CENTERIMAGE))
                $LabelArray = FileRead($sFilePath)
                GUICtrlCreateLabel($LabelArray, 10, 10, 590, 100)
                GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
                GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

            GUISetState(@SW_SHOW) ;Show GUI
            While 1
            Local $msg = GUIGetMsg()

                If $msg = "" Then
                    For $i = 0 To UBound($aArray) - 1 ; Loop through the array.
                        $var = Ping($aArray[$i], 1000)
                        If $var Then; also possible:  If @error = 0 Then ...
                            GUICtrlCreateIcon($green, -1, 290, 10, 16, 16)
                            ConsoleWrite("Online, roundtrip was:" & $var & @CRLF)
                            Sleep(1000)
                        Else
                            GUICtrlCreateIcon($red, -1, 290, 10, 16, 16)
                            ConsoleWrite("Host Unresponsive " & $aArray[$i] & @CRLF)
                            SoundPlay($ErrSound, 0)
                            Sleep(3000)
                        EndIf
                    Next
                        $log = FileOpen(@TempDir & "\Uptime_Monitor\Log.txt", 1)
                        If $log = -1 Then
                            Exit
                        EndIf
                        FileWriteLine($log, "End Of Loop - Reprocessing..." & @CRLF)
                        FileClose($log)
                ElseIf $msg = $GUI_EVENT_CLOSE Then
                    ExitLoop
                    GUIDelete()
                EndIf
            WEnd
        EndIf
EndFunc

I'm aware the GUI is not looking great currently and will address that once it is working as required. I welcome any suggestions or advice as i am sure some of the things i have done could be done in a better way - I just don't know how, still learning  :thumbsup:

Thank you,

Dan

ResFiles.zip

Link to comment
Share on other sites

To be honest, when I see a script where the member is installing / copying files across my computer and wants me to ping a load of addresses, I just click out of the thread.

Boil your problem down to a simple example without all the nonsense, and I guarantee you'll get help within the hour.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hello JohnOne,

If i could do that quickly i would, its not like i created this in 5 minutes, its taken me a long time to get this far so to pull it back to pieces will take me just as long and i will be no further along than i am now.

As for the files its installing, I think if you add this line to the bottom of the script everything it does should be gone once you close the GUI.

DirRemove(@TempDir & "\Uptime Monitor\", 1)

I don't understand the issue with the ping as that's the point of the script, if its a success you get green, if not a success you get red, the 3 items generated are dummy entries so you could delete all 3 entries using the first GUI and then add for example "localhost" which should give you a green icon, add a second entry to something that wont ping and you should see it change to red.

Cheers

Dan

Link to comment
Share on other sites

Hows this?

#include <Inet.au3>
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <GuiListView.au3>

;Disable tray icon pause
AutoItSetOption("TrayAutoPause",0)

;Setup Gui icons
Global $green = ("C:\Program Files\AutoIt3\Icons\au3.ico")
Global $red = ("C:\Program Files\AutoIt3\Icons\au3script_v10.ico")

;Set additional global variables
Global $sort = False

;######################;
;;;;;;;Functions;;;;;;;;
;######################;



;Launch MonitorGUI function
MonitorGUI()

;MonitorGUI funtction
Func MonitorGUI()

    Global $iW = 320, $iH = 180, $iT = 52, $iB = 52, $iLeftWidth = 150, $iGap = 10, $hMainGUI
    Local $sMainGuiTitle = "System Monitor"
    ;Local $aArray = FileReadToArray($sFilePath)
    Local $aArray = ["localhost", "uncontactablehost"]
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
        Else

            $hMainGUI = GUICreate($sMainGuiTitle, $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
                ;$LabelArray = FileRead($sFilePath)
                $LabelArray = $aArray
                ;GUICtrlCreateLabel($LabelArray, 10, 10, 590, 100)
                GUICtrlCreateLabel($aArray[0], 10, 10, 590, 100)
                GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
                GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
                GUICtrlCreateLabel($aArray[1], 10, 30, 590, 100)
                GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
                GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

            GUISetState(@SW_SHOW) ;Show GUI
            While 1
            Local $msg = GUIGetMsg()

                If $msg = "" Then
                    For $i = 0 To UBound($aArray) - 1 ; Loop through the array.
                        $var = Ping($aArray[$i], 1000)
                        If $var Then; also possible:  If @error = 0 Then ...
                            GUICtrlCreateIcon($green, -1, 290, 10, 16, 16)
                            ConsoleWrite("Online, roundtrip was:" & $var & @CRLF)
                            Sleep(1000)
                        Else
                            GUICtrlCreateIcon($red, -1, 290, 10, 16, 16)
                            ConsoleWrite("Host Unresponsive " & $aArray[$i] & @CRLF)

                            Sleep(3000)
                        EndIf
                    Next
                ElseIf $msg = $GUI_EVENT_CLOSE Then
                    ExitLoop
                    GUIDelete()
                EndIf
            WEnd
        EndIf
EndFunc
Link to comment
Share on other sites

So when the GUI loads you should see 2 labels:

localhost

uncontactablehost

The loop pings the first "localhost" and then should place an icon next to it to indicate online like the below:

localhost                  :thumbsup:

uncontactablehost

The loop then pings the second "uncontactablehost" and it should place an icon next to that label like this:

localhost                 :thumbsup:

uncontactablehost       :x

But what i get is:

localhost                   :x

uncontactablehost

Is that what you see?

Edited by goss34
Link to comment
Share on other sites

Notice in your array, I have added a y coordinate which corresponds to the label and employed it also as the y coordinate of the icon.

#include <Inet.au3>
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <GuiListView.au3>

;Disable tray icon pause
AutoItSetOption("TrayAutoPause", 0)

;Setup Gui icons
Global $green = ("C:\Program Files\AutoIt3\Icons\au3.ico")
Global $red = ("C:\Program Files\AutoIt3\Icons\au3script_v10.ico")

;Set additional global variables
Global $sort = False

;######################;
;;;;;;;Functions;;;;;;;;
;######################;



;Launch MonitorGUI function
MonitorGUI()

;MonitorGUI funtction
Func MonitorGUI()

    Global $iW = 320, $iH = 180, $iT = 52, $iB = 52, $iLeftWidth = 150, $iGap = 10, $hMainGUI
    Local $sMainGuiTitle = "System Monitor"
    ;Local $aArray = FileReadToArray($sFilePath)
    Local $aArray[2][2] = [["localhost", 10], ["uncontactablehost", 30]]

    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
    Else

        $hMainGUI = GUICreate($sMainGuiTitle, $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
        ;$LabelArray = FileRead($sFilePath)
        $LabelArray = $aArray
        ;GUICtrlCreateLabel($LabelArray, 10, 10, 590, 100)
        GUICtrlCreateLabel($aArray[0][0], 10, $aArray[0][1], 590, 100)
        GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
        GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
        GUICtrlCreateLabel($aArray[1][0], 10, $aArray[1][1], 590, 100)
        GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
        GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

        GUISetState(@SW_SHOW) ;Show GUI
        While 1
            Local $msg = GUIGetMsg()

            If $msg = "" Then
                For $i = 0 To UBound($aArray) - 1 ; Loop through the array.
                    $var = Ping($aArray[$i][0], 1000)
                    If $var Then; also possible:  If @error = 0 Then ...
                        GUICtrlCreateIcon($green, -1, 290, $aArray[$i][1], 16, 16)
                        ConsoleWrite("Online, roundtrip was:" & $var & @CRLF)
                        Sleep(1000)
                    Else
                        GUICtrlCreateIcon($red, -1, 290, $aArray[$i][1], 16, 16)
                        ConsoleWrite("Host Unresponsive " & $aArray[$i][0] & @CRLF)

                        Sleep(3000)
                    EndIf
                Next
            ElseIf $msg = $GUI_EVENT_CLOSE Then
                ExitLoop
                GUIDelete()
            EndIf
        WEnd
    EndIf
EndFunc   ;==>MonitorGUI
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I see it but i think where i have had to strip out my code to make it easier for you to run its now not set as it was and i don't think i can replicate those changes into my code.

For example in my original code i had the labels created using:

$LabelArray = FileRead($sFilePath)
    GUICtrlCreateLabel($LabelArray, 10, 10, 590, 100)
    GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

I edited it to this (see here i am specifying which item in the array to label and where to place it - before i was not doing that):

Local $aArray = ["localhost", "uncontactablehost"]
GUICtrlCreateLabel($aArray[0], 10, 10, 590, 100)
GUICtrlCreateLabel($aArray[1], 10, 30, 590, 100)

 

Now you have edited to:

Local $aArray[2][2] = [["localhost", 10], ["uncontactablehost", 30]]
        GUICtrlCreateLabel($aArray[0][0], 10, $aArray[0][1], 590, 100)
        GUICtrlCreateLabel($aArray[1][0], 10, $aArray[1][1], 590, 100)

I understand (90%) how that now works but how can i incorporate that when my array data doesn't show a y coordinate?

Cheers

Dan

Edited by goss34
Link to comment
Share on other sites

Would mean changing the way you get data from your file.

Personally I would use an ini file similar to...

[one]
host = 192.168.0.1
ypos = 10
 
[two]
host = 192.168.0.2
ypos = 30
 
[three]
host = 192.168.0.3
ypos = 50
 
[four]
host = 192.168.0.4
ypos = 70

 

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Is there not another way - i started the whole process using an INI but i couldn't get the first GUI (which you currently cant see in this example) to display correctly in the listview and then it would mean when entering a new server they would need to also know what position to enter for the label (which a normal person wouldn't know).

Original file is just a text file in this format:

localhost
uncontactablehost
uncontactablehost2
uncontactablehost3
Link to comment
Share on other sites

Yes, you can create a 2D array from your 1D array...

$aFirst = FileReadToArray("ping.txt")

_ArrayDisplay($aFirst)

Local $aArray[UBound($aFirst)][2]

$Initial_Y_Coordinate = 10

For $i = 0 To UBound($aArray) -1
    $aArray[$i][0] = $aFirst[$i] ; add host name
    $aArray[$i][1] = $Initial_Y_Coordinate ; add coord
    $Initial_Y_Coordinate += 20 ; incrment coord.
Next

_ArrayDisplay($aArray)
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

The way i have coded this might not make it possible as im using 2 different arrays, one for the label creation with fileread and the icon creation using is a filereadtoarray. The reason i did this was because i couldn't get the label to create each array item. The full function code is below:

;MonitorGUI funtction
Func MonitorGUI()

    Global $iW = 320, $iH = 180, $iT = 52, $iB = 52, $iLeftWidth = 150, $iGap = 10, $hMainGUI
    Local $sMainGuiTitle = "System Monitor"
    Local $sFooter = "2015 © MonitorGUI"
    Local $aArray = FileReadToArray($sFilePath)
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
        Else

            $hMainGUI = GUICreate($sMainGuiTitle, $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
            GUISetIcon($green, $hMainGUI)
            GUICtrlCreateLabel($sFooter, 10, $iH - 34, $iW - 20, 17, BitOR($SS_LEFT, $SS_CENTERIMAGE))
                $LabelArray = FileRead($sFilePath)
                GUICtrlCreateLabel($LabelArray, 10, 10, 590, 100)
                GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
                GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

            GUISetState(@SW_SHOW) ;Show GUI
            While 1
            Local $msg = GUIGetMsg()

                If $msg = "" Then
                    For $i = 0 To UBound($aArray) - 1 ; Loop through the array.
                        $var = Ping($aArray[$i], 1000)
                        If $var Then; also possible:  If @error = 0 Then ...
                            GUICtrlCreateIcon($green, -1, 290, 10, 16, 16)
                            ConsoleWrite("Online, roundtrip was:" & $var & @CRLF)
                            Sleep(1000)
                        Else
                            GUICtrlCreateIcon($red, -1, 290, 10, 16, 16)
                            ConsoleWrite("Host Unresponsive " & $aArray[$i] & @CRLF)
                            SoundPlay($ErrSound, 0)
                            Sleep(3000)
                        EndIf
                    Next
                        $log = FileOpen(@TempDir & "\Uptime_Monitor\Log.txt", 1)
                        If $log = -1 Then
                            Exit
                        EndIf
                        FileWriteLine($log, "End Of Loop - Reprocessing..." & @CRLF)
                        FileClose($log)
                ElseIf $msg = $GUI_EVENT_CLOSE Then
                    ExitLoop
                    GUIDelete()
                EndIf
            WEnd
        EndIf
EndFunc

You can see here i create/use both arrays here:

>>>>>  Local $aArray = FileReadToArray($sFilePath)
        If @error Then
            MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
        Else

            $hMainGUI = GUICreate($sMainGuiTitle, $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
            GUISetIcon($green, $hMainGUI)
            GUICtrlCreateLabel($sFooter, 10, $iH - 34, $iW - 20, 17, BitOR($SS_LEFT, $SS_CENTERIMAGE))
>>>>>               $LabelArray = FileRead($sFilePath)
                GUICtrlCreateLabel($LabelArray, 10, 10, 590, 100)
                GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
                GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

So the label uses $LabelArray (created from the same text file) where as the icon uses $aArray as below:

>>>>> For $i = 0 To UBound($aArray) - 1 ; Loop through the array.
                        $var = Ping($aArray[$i], 1000)
                        If $var Then; also possible:  If @error = 0 Then ...
                            GUICtrlCreateIcon($green, -1, 290, 10, 16, 16)
                            ConsoleWrite("Online, roundtrip was:" & $var & @CRLF)
                            Sleep(1000)
                        Else
                            GUICtrlCreateIcon($red, -1, 290, 10, 16, 16)
                            ConsoleWrite("Host Unresponsive " & $aArray[$i] & @CRLF)
                            SoundPlay($ErrSound, 0)
                            Sleep(3000)
                        EndIf
                    Next

Because of this i am unsure where to start, i am happy to get rid of $LabelArray if you can help me to get the "GUICtrlCreateLabel($LabelArray, 10, 10, 590, 100)" to populate the GUI using $Array instead. That may make it easier to implement the 2d array - at the moment i don't understand it well enough to be able to implement it in my code.

Cheers

Dan

Edited by goss34
Link to comment
Share on other sites

Thanks, this is going to take a while to get my head around, i will reply when i think i have made some progress  :sweating:

It should not really be that hard once you get a grip on it, it's basically changing a bit of code..

 

This...

$aArray = FileReadToArray($sFilePath)
For this...

$aFirst = FileReadToArray($sFilePath)

Local $aArray[UBound($aFirst)][2]

$Initial_Y_Coordinate = 10

For $i = 0 To UBound($aArray) -1
    $aArray[$i][0] = $aFirst[$i]
    $aArray[$i][1] = $Initial_Y_Coordinate
    $Initial_Y_Coordinate += 20
Next
And 

 

A bit of jiggery pokery with your labels, like creating them in a loop, using the array....

For $y = 0 To UBound($aArray) - 1
    GUICtrlCreateLabel($aArray[0][0], 10, $aArray[0][1], 590, 100)
    GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Next
etc... Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I'm confused  :doh: 

For $y = 0 To UBound($aArray) - 1
    GUICtrlCreateLabel($aArray[0][0], 10, $aArray[0][1], 590, 100)
    GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Next

If i use the above then from what i can tell i need to create the labels manually rather than them being read in from the file? e.g.

For $y = 0 To UBound($aArray) - 1
    GUICtrlCreateLabel($aArray[0][0], 10, $aArray[0][1], 590, 100)
    GUICtrlCreateLabel($aArray[1][0], 10, $aArray[1][1], 590, 100) <<
    GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Next

The idea is that array can grow and the labels will create by reading the file. As i said im confused so i am probably misunderstanding how your instructing me.

Please bear with me, I have only managed one successful array in my time previously and that's the first function in this full code so i am still trying to get to grips with what each part does (i removed all my comments so you could read this easier and now im having an issue with it haha).

Ta

Dan

Link to comment
Share on other sites

I made an error is all, look here's a simple example.

$GUI = GUICreate("GUI")

$aFirst = FileReadToArray("ping.txt")

Local $aArray[UBound($aFirst)][2]

$Initial_Y_Coordinate = 10

For $i = 0 To UBound($aArray) - 1
    $aArray[$i][0] = $aFirst[$i] ; add host name
    $aArray[$i][1] = $Initial_Y_Coordinate ; add coord
    $Initial_Y_Coordinate += 20 ; incrment coord.
Next

For $y = 0 To UBound($aArray) - 1
    GUICtrlCreateLabel($aArray[$y][0], 10, $aArray[$y][1], 590, 100)
    GUICtrlSetFont(-1, 11, 800, 0, "Verdana", 5)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP); + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Next

GUISetState()

Do
    ;nothing
Until GUIGetMsg() = -3
Exit

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...