31290

File into list view and other

23 posts in this topic

#1 ·  Posted (edited)

Hi Everyone, Happy New Year :sorcerer:

Well, I have a script that gather information about a given switch here at work that output data in a txt file:

txt.thumb.png.f40d19f18ad3e27fa32e256139

What I'd like to do first is to put the file in a list view with the possibility to sort the ports by VLAN, by ports or by Status (and also delete all that concern Duplex / Speed / Type).

In a second time, I'd like to bold and color "connected" in green / "disconnected" in red and "err-disabled" in gray. Then, I'd like also to apply a certain color depending on the VLAN number (I have the list of them).

And to finish (sorry ^^) when I double click on a list item, I'd like to retrieve information of the selected line for me to do some operation on it.

I know this is quite an ask but this is something I don't know how to (don't worry, I've done some researches before) do and also, I'm not familiar with arrays at all.

Many thanks for those who can help :)

I've uploaded the output txt file: EPES18.txt

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

31290,

This should get you started:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <GuiListView.au3>

; Read file and replace tabs
$sContent = StringReplace(FileRead("EPES18.txt"), @TAB, " ")
; Expand possible single space before connection status
$sExpanded = StringRegExpReplace($sContent, "(\x20(connected|notconnect|err-disabled))", " $1")
; Replace multiple spaces with | delimiter - max 19 to allow for empty fields
$sDelimed = StringRegExpReplace($sExpanded, "(\x20{2,19})", "|")
; Split on @CRLF
$aLines = StringSplit($sDelimed, @CRLF, $STR_ENTIRESPLIT)

;_ArrayDisplay($aLines, "", Default, 8)

$hGUI = GUICreate("Test", 500, 500)

; Create ListView with first 4 headers
$cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[1], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), 10, 10, 480, 380)
GUICtrlSetBkColor($cLV, 0x808080)
; Set column widths
For $i = 0 To 3
    _GUICtrlListView_SetColumnWidth($cLV, $i, 110)
Next
; Add content of first 4 fields in each line
For $i = 2 To $aLines[0]
    $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($alines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), $cLV)
    ; Colour according to status
    If StringInStr($alines[$i], "|connected|") Then
        GUICtrlSetColor($cLVItem, 0x00FF00)
    ElseIf StringInStr($alines[$i], "|notconnect|") Then
        GUICtrlSetColor($cLVItem, 0xFF0000)
    Else
        GUICtrlSetColor($cLVItem, 0xC4C4C4)
    EndIf

Next

GUISetState()

; Set sort state
Local $aSortSense[_GUICtrlListView_GetColumnCount($cLV)]

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd



Func _WM_NOTIFY($hWnd, $imsg, $wParam, $lParam)

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW

    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode

        Case $LVN_COLUMNCLICK
            ; Get column index
            Local $iCol = DllStructGetData($tStruct, 5)
            ; Sort column
            _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol)
        Case $NM_DBLCLK
            $iRow = DllStructGetData($tStruct, 4)
            ; Row 0 in ListView is row 2 in the array
            MsgBox($MB_SYSTEMMODAL, "Row Data", $aLines[$iRow + 2])
    EndSwitch

EndFunc

M23

Edit; I amended the file slightly to add some "err-disabled" lines:

 

EPES18.txt

Edited by Melba23
2 people like this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23!

That's exactly this kind I'd like!!! So much thanks!!! Now I can try to understand how things work and for sure, my knowledge will grow. :)

Is it possible to color vlans according to their numbers stored in a txt file? For example, if Vlan 13 or Vlan 31 is in a txt file, then color it in bleu. In fact, I'd like to be able to color items in a row depending on their value... Not sure this is well expressed :/

Therefore, and as you can see, if I sort the list by the ports twice, I got this:

ports.thumb.png.b39dd05ab6df36508c85a76e

Any ideas?

 

Many thanks again!


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

31290,

Colouring individual sub-items on a line is much more complicated - LarsJ shows how you can do it here.

Sorting is done alphabetically - so there is no simple way to avoid that return listing. The alternative would be to extract the data into an array, split the alpha and numeric sections, sort the latter numerically, recombine and then reload the ListView - certainly doable, but a bit of a faff.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23, 

Yeah, that seems to be a hard job. So in this case, do you think locking up sorting in column only is possible?

One last question for you and I won't disturb you anymore :)

How can I isolate every items? I tried to play with DllStructGetData but it seems that this is not working. I'd like to get the portnumber (item one), the description (item 2), the state (item 3) and the Vlan (item 4)

data.thumb.png.f875e79f8b8165e60aa89fc8b

By the way, huge thanks to you for the help you provided to me! :drinks:


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

31290,

locking up sorting in column only is possible

Do you mean that you want to prevent sorting in certain columns?

To get the separate items from the data, use StringSplit to get the different elements into an array and then select the ones you want:

Case $NM_DBLCLK
    $iRow = DllStructGetData($tStruct, 4)
    ; Row 0 in ListView is row 2 in the array
    $sData = $aLines[$iRow + 2]
    ; Split
    $aData = StringSplit($sData, "|")
    MsgBox($MB_SYSTEMMODAL, "Row Data", $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4])

By the way, do not use a MsgBox inside the handler in your final script - I only did so here for a quick demonstration. I suggest you set a flag or action a dummy control so that you do not block the handler's return.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks M23 :) that's very very kind of you. 

31290,

Do you mean that you want to prevent sorting in certain columns?

 

Yes, I did a typo here :) People will need to sort columns but if not possible, I'll add a label warning them. But thinking about it, I think this won't be possible... But you never know.

By the way, do not use a MsgBox inside the handler in your final script - I only did so here for a quick demonstration. I suggest you set a flag or action a dummy control so that you do not block the handler's return.

M23

Yes, some items will be set to a global variable for future treatment, set in a txt file and sent to the switch for configuring a port according to our needs :)

Thanks.

 


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

31290,

If you want to prevent sorting certain columns, then just check which column was clicked inside the handler - this prevents the first column being sorted:

Case $LVN_COLUMNCLICK
    ; Get column index
    Local $iCol = DllStructGetData($tStruct, 5)
    If $iCol <> 0 Then
        ; Sort column
        _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol)
    EndIf

M23:

 

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

So Cool M23! You rock, as usual!

Many many thanks again for your precious help! Keep going :)

Bye Bye


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

31290,

Here is LarsJ's code integrated into mine - I enjoyed doing that:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <GuiListView.au3>

; Read file and replace tabs
$sContent = StringReplace(FileRead("EPES18.txt"), @TAB, " ")
; Replace orphaned dashes
$sNoDashes = StringReplace($sContent, " - ", "  ")
; Expand possible single space before connection status
$sExpanded = StringRegExpReplace($sNoDashes, "(\x20(connected|notconnect|err-disabled))", " $1")
; Replace multiple spaces with | delimiter - max 19 to allow for empty fields
$sDelimed = StringRegExpReplace($sExpanded, "(\x20{2,19})", "|")
; Split on @CRLF
$aLines = StringSplit($sDelimed, @CRLF, $STR_ENTIRESPLIT)
;_ArrayDisplay($aLines, "", Default, 8)

$hGUI = GUICreate("Test", 500, 500)

; Create ListView with first 4 headers
$cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[1], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), 10, 10, 480, 380)
; Set column widths
For $i = 0 To 3
    _GUICtrlListView_SetColumnWidth($cLV, $i, 110)
Next
; Add content of first 4 fields in each line
For $i = 2 To $aLines[0]
    $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), $cLV)
Next

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

; Set sort state
Local $aSortSense[_GUICtrlListView_GetColumnCount($cLV)]

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd



Func _WM_NOTIFY($hWnd, $imsg, $wParam, $lParam)

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW

    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode



        Case $LVN_COLUMNCLICK
            ; Get column index
            Local $iCol = DllStructGetData($tStruct, 5)
            If $iCol <> 0 Then
                ; Sort column
                _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol)
            EndIf

        Case $NM_DBLCLK
            $iRow = DllStructGetData($tStruct, 4)
            ; Row 0 in ListView is row 2 in the array
            $sData = $aLines[$iRow + 2]
            ; Split
            $aData = StringSplit($sData, "|")
            ConsoleWrite("Row Data: " & $aData[1] & " - " & $aData[2] & " - " & $aData[3] & " - " & $aData[4] & @‌CRLF)

        Case $NM_CUSTOMDRAW
            Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
            Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
            Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                Case $CDDS_PREPAINT
                    ; Before the paint cycle begins
                    Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations
                Case $CDDS_ITEMPREPAINT
                    ; Before painting an item
                    Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations
                Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                    ; Before painting a subitem

                    Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
                    Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
                    ; Gte text of item
                    $sText = _GUICtrlListView_GetItemText($cLV, $iItem, $iSubItem)
                    ; Set default back colour
                    $iBkColour = 0xC0B0B0
                    ; Now check for our spoecific items
                    Switch $iSubItem

                        Case 2 ; connection
                            Switch $sText

                                Case "connected"
                                    $iBkColour = 0x00FF00
                                Case "notconnect"
                                    $iBkColour = 0x0000FF
                                Case "err-disabled"
                                    $iBkColour = 0xC4C4C4
                            EndSwitch

                        Case 3 ; vlan

                            Switch $sText

                                Case "trunk"
                                    $iBkColour = 0x00FFFF
                                Case "1"
                                    $iBkColour = 0xFFFF00
                                Case "10"
                                    $iBkColour = 0xC4FFC4
                                Case "13"
                                    $iBkColour = 0xFF00FF
                            EndSwitch

                    EndSwitch

                    ; Set required back colour
                    DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", $iBkColour)

                    Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors

            EndSwitch



    EndSwitch



EndFunc   ;==>_WM_NOTIFY

It looks as if the file parsing could do with a bit more work - there are a couple of lines where the delimiters are not correct. It does not help that the file uses a mixture of spaces and tabs to separate the items on each line - and on some lines there are items missing. Can you get the file in a more reasonable CSV format or are you stuck with what you have posted?

M23

Edit: Recoded the file parsing - it now works for the test file, but I would still recommend trying to get a better delimited file initially as the parsing requirements are a bit arbitrary at the moment.

Edited by Melba23
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23, 

I have no words for that! Really! That's totally awesome :D Thanks!

To give you the answer, I cannot output to any other file extension because of putty (and more especially plink). If you want, here the code I use to gather a switch information:

Run(@ComSpec & ' /c '&$testvariable&'PLINK.EXE '&$currentSwitch&' -l '&$username&' -pw '&$ClearPwd&' sh ver > '&$testvariable&'info'&$currentSwitch&'.txt', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

For sure, a tab delimited file would be easier to deal with. In that case, isn't that possible to transform the txt file in a tab delimited csv one?
Because on some lines, I have this:

2016-01-14_14-31-06.thumb.png.01974bbeeb

The port state is in the Vlan column :/

Thanks :)


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

31290,

As I mentioned above, the file contains both spaces and tabs as well as many missing "Name" fields - all this makes the converting of the file to a suitably delimited form quite tricky. I will look again at how it might be done, but no promises.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

31290,

I have completely recoded the delimiter parsing section to deal with the annoying "Name" section - please test this and see if it works for you:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <GuiListView.au3>

; Read file into array
$aLines = FileReadToArray("EPES18.txt")

; Deal with title line
$aLines[0] = StringRegExpReplace($aLines[0], "(\x20+)", "|")
; Now the other lines
For $i = 1 To UBound($aLines) - 1
    ; Extract line
    $sLine = $aLines[$i]
    ; Replace tabs with spaces
    $sLine = StringReplace($sLine, @TAB, " ")
    ; Extract possible name field
    $sName = StringRegExpReplace($sLine, "(?U)^.*(\x20.*\x20)(connected|notconnect|err-disabled).*$", "$1")
    ; Convert multiple spaces to singles
    $sStrippedName = StringRegExpReplace($sName, "\x20+", " ")
    ; Set placeholder if no name field
    If $sStrippedName = " " Then $sStrippedName = " ~ "
    ; Replace original name string in line with stripped version - add spaces to ensure multiple spaces before and after
    $sLine = StringReplace($sLine, $sName, " " & $sStrippedName & " ")
    ; Set delimiters by replacing multiple spaces
    $sLine = StringRegExpReplace($sLine, "(\x20{2,19})", "|")
    ; Remove placeholders
    $sLine = StringReplace($sLine, "~", "")
    ; Replace existing line with delimited line
    $aLines[$i] = $sLine

Next

$hGUI = GUICreate("Test", 500, 500)

; Create ListView with first 4 headers
$cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[0], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), 10, 10, 480, 380)
; Set column widths
For $i = 0 To 3
    _GUICtrlListView_SetColumnWidth($cLV, $i, 110)
Next
; Add content of first 4 fields in each line
For $i = 1 To UBound($aLines) - 1
    $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), $cLV)
Next

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

; Set sort state
Local $aSortSense[_GUICtrlListView_GetColumnCount($cLV)]

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch



WEnd







Func _WM_NOTIFY($hWnd, $imsg, $wParam, $lParam)

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW



    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode







        Case $LVN_COLUMNCLICK
            ; Get column index
            Local $iCol = DllStructGetData($tStruct, 5)
            If $iCol <> 0 Then
                ; Sort column
                _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol)
            EndIf



        Case $NM_DBLCLK
            $iRow = DllStructGetData($tStruct, 4)
            ; Row 0 in ListView is row 2 in the array
            $sData = $aLines[$iRow + 2]
            ; Split
            $aData = StringSplit($sData, "|")
            ConsoleWrite("Row Data: " & $aData[1] & " - " & $aData[2] & " - " & $aData[3] & " - " & $aData[4] & @CRLF)

        Case $NM_CUSTOMDRAW
            Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
            Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
            Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                Case $CDDS_PREPAINT
                    ; Before the paint cycle begins
                    Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations
                Case $CDDS_ITEMPREPAINT
                    ; Before painting an item
                    Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations
                Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                    ; Before painting a subitem



                    Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
                    Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
                    ; Gte text of item
                    $sText = _GUICtrlListView_GetItemText($cLV, $iItem, $iSubItem)
                    ; Set default back colour
                    $iBkColour = 0xC4C4C4
                    ; Now check for our spoecific items
                    Switch $iSubItem



                        Case 2 ; connection
                            Switch $sText



                                Case "connected"
                                    $iBkColour = 0x00FF00
                                Case "notconnect"
                                    $iBkColour = 0x0000FF
                                Case "err-disabled"
                                    $iBkColour = 0xC4C4C4
                            EndSwitch



                        Case 3 ; vlan



                            Switch $sText



                                Case "trunk"
                                    $iBkColour = 0x00FFFF
                                Case "1"
                                    $iBkColour = 0xFFFF00
                                Case "10"
                                    $iBkColour = 0xC4FFC4
                                Case "13"
                                    $iBkColour = 0xFF00FF
                            EndSwitch



                    EndSwitch



                    ; Set required back colour
                    DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", $iBkColour)

                    Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors



            EndSwitch







    EndSwitch







EndFunc   ;==>_WM_NOTIFY

If you still have problems, then please let me see the file containing the lines causing difficulty so I can refine the process further.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23, 

This is perfectly working now, no more bad formatting.

I'd like to thank you again for all you did for me, have a great weekend (if any ^^). I'll buy you a beer sometimes!

Au revoir et merci encore! (Yeah, I'm French ^^) 


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

31290,

Il n'y a pas de quoi.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23, 

I Need one more little hand, I promise, I stop after that :)

I realized that I was able to gather one last very essential value to the list view, but that one is coming from an other txt file (still no csv).

What I'd like to do, is to integrate a fifth column, named "IP Phone" (or something else I don't care for now) with "Yes" or "No" depending if the corresponding port is listed in the output text file. 

I've attached 2 of them so you can see the structure of them (the idmul.txt that all the ports are configured to support ip phone, VLAN 100 for us)

ipphone.thumb.png.6f2183384b8a6b45cf0f44
I hope my explanations are clear enough for you ;) So much thanks :D 

idmul.txt

id.txt

idmul.txt


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

31290,

Easy! Just replace the existing GUI and ListView creation lines in the earlier script with these:

; This is where we parse the main file

; Read IP Phone ID file
$sID = Fileread("id.txt")

$hGUI = GUICreate("Test", 500, 500)

; Create ListView with first 4 headers plus "IP Phone"
$cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[0], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & "|IP Phone", 10, 10, 480, 380)
; Set column widths
For $i = 0 To 4
    _GUICtrlListView_SetColumnWidth($cLV, $i, 90)
Next
; Add content of first 4 fields in each line plus the IP Phone result
For $i = 1 To UBound($aLines) - 1
    ; Assume not IP Phone
    $sIPPhone = "|N"
    ; Look for the port ID in the file - it will be preceded by a space and followed by either a comma or an EOL
    If StringRegExp($sID, " " & StringRegExpReplace($aLines[$i], "(?U)^(.*)\|.*$", "$1") & "[,\x0D]") Then
        ; If found change the set value
        $sIPPhone = "|Y"
    EndIf
    ; Add fields and IP Phone to the ListView
    $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & $sIPPhone, $cLV)
    Next

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

That works fine for me with your test files - does it work for you too?

And never be afraid to ask - I come here to help and to keep my "little grey cells" in good condition!

M23

 

 

 

Edited by Melba23
Additional comments

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23, 

On 1/15/2016 at 5:50 PM, Melba23 said:

And never be afraid to ask - I come here to help and to keep my "little grey cells" in good condition!

That's very kind of you because with your help, I can learn more about things I don't handle. :)

Yes, it is working fine with my files, just a few ajustments to fill my needs bu this is perfect.

One question though :D :

I'm trying to get the value of the IPPhone variable defined by this:

Global $sIPPhone = "|Not Set"
    ; Look for the port ID in the file - it will be preceded by a space and followed by either a comma or an EOL
    If StringRegExp($sID, " " & StringRegExpReplace($aLines[$i], "(?U)^(.*)\|.*$", "$1") & "[,\x0D]") Then
        ; If found change the set value
       Global $sIPPhone = "|Set"
    EndIf

and doing this:

Global $aIPPhone = StringTrimLeft($sIPPhone,1)
            ; Global $aIPPhone = _GUICtrlListView_GetItemTextArray ( $cLV , 5)
            MsgBox($MB_SYSTEMMODAL, "Row Data", $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4] & @CRLF & $aIPPhone )

All I get is the "Not Set" value when double clicking on the line were it is "Set":

2016-01-18_09-38-15.png.f8c25723a80d528b
I also tried to get the value with the "_GUICtrlListView_GetItemTextArray" function and by creating an other array but nothing seems to work here :/ Can you please help on this?

Oh and I just saw something: When I move the msgbox into the listview, every thing goes white :) Is it something expected? 

That was just a remark as when a technician will double click on a port, the listview GUI will be disabled and enabled when operation on said port will be acknowleded.

Thanks :)


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites

31290,

This works fine for me:

Case $NM_DBLCLK
    $iRow = DllStructGetData($tStruct, 4)
    ConsoleWrite("Row Data: " & _GUICtrlListView_GetItemTextString($cLV, $iRow) & @CRLF)

As I mentioned above, you should not be using a MsgBox (or any other blocking function) inside a Windows message handler - when the Help file says you should return from the handler ASAP it means it! By blocking the handler you are blocking the flow of Windows messages inside the app and risking a serious crash. In this case, you are blocking the WM_NOTIFY messages which we use to colour the ListView when repainting - hence you get no repaint.  If you want to test, use a ConsoleWrite as I did above, or a flag in the idle loop (let me know if you want to see how that can be done).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

M23, 

I understood what you said about not using a MsgBox, but I wanted to be sure that all values (port name, description, vlan and IPPhone) were get because I have to display them separately in a new GUI when double clicking on a port. After that, I have operations to perform on said values (change Vlan, change description, etc...)

That's why:

MsgBox($MB_SYSTEMMODAL, "Row Data", $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4] & @CRLF & $aIPPhone )

Is a way for me to be sure of that. To avoid the loss of painting, I can minimize the GUI while the Ports Operations GUI is opened and in anycases, I have to reload almost everything to display updates (generate all the files, etc... But I've already done that)

28 minutes ago, Melba23 said:

If you want to test, use a ConsoleWrite as I did above, or a flag in the idle loop (let me know if you want to see how that can be done).

If you have time, yes of course, all is good to take :)

Thanks :)


~~~ Doom Shall Never Die, Only The Players ~~~

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

    • usmiv4o
      By usmiv4o
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.4.3 Author: usmiv4o Script Function: AutoIt script to check if files in directory are changed. It is usefull for security contra-inteligense measures. Function Name: LoadTripwireDB() Description: Loads database (text file tripwire.txt) and compare files in /test folder for changes. compares Hash (MD5) checksums. If they are not the same starts Initial() Function Name: Initial() Description: Checks directory and makes index of files and their MD5 checksums in text file (tripwire.txt) Function Name: Hush() Description: Checks file and returns its MD5 checksum. Requirement(s): Windows XP Return Value(s): On Success - Returns true. Files are the same as before. On Failure - return false. Example: LoadTripwireDB() #ce ---------------------------------------------------------------------------- #include <Crypt.au3> #include <File.au3> #include <Array.au3> $sDir = @ScriptDir & "\Test" $sFilePath = @ScriptDir & "\tripwire.txt" Func Hush(ByRef $sFile) $sRead = FileOpen( $sFile) $dHash = _Crypt_HashData($sRead, $CALG_MD5) ; Create a hash of the text entered. ConsoleWrite("Hash of file " & $sFile & " is " & $dHash & @CRLF) EndFunc ;ConsoleWrite("Files in Dir are " & $aScriptDir[0] & @CRLF) ;$sFilePath = @ScriptDir & "\Examples.txt" ;_FileWriteFromArray($sFilePath, $aScriptDir, 1) ;_ArrayDisplay($aScriptDir, "1D display") Func Initial() $aScriptDir = _FileListToArray($sDir) for $i = 1 To UBound($aScriptDir) - 1 $dHash = _Crypt_HashData($i, $CALG_MD5) ;ConsoleWrite("File " & $aScriptDir[$i] & " is " & $dHash & @CRLF) ConsoleWrite($aScriptDir[$i] & ":" & $dHash & @CRLF) ;Hush($aScriptDir[$i]) ;FileWrite $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") EndIf FileWrite($hFileOpen, $aScriptDir[$i] & ":" & $dHash & @CRLF) Next EndFunc Func Monitor() $aScriptDir = _FileListToArray($sDir) for $i = 1 To UBound($aScriptDir) - 1 Next EndFunc Func LoadTripwireDB() $comparison_ok = false $dArray = _FileListToArray($sDir) ;directory $dArray0 = UBound($dArray) - 1 $fArray = FileReadToArray($sFilePath) ;file $fArray0 = UBound($fArray) ;_ArrayDisplay($dArray, "files array") if $dArray0 = $fArray0 Then ; are file same as recorded in txt file? ;ConsoleWrite("files in monitoring dir: " & $dArray[0] & " = file recorded: " & $fArray0 & @CRLF & $fArray[0]& @CRLF) for $i = 1 To UBound($dArray) - 1 ;ConsoleWrite("i = " & $i & @CRLF) $dHash = _Crypt_HashData($i, $CALG_MD5) ;binary ;$dHash = BinaryToString($dHash) $ffhash = StringSplit( $fArray[$i-1],":") $fhash = $ffhash[2] ;ConsoleWrite("IsBinary $dHash " & IsBinary($dHash) & @CRLF) if $dHash = $fhash Then ;if compared hashes are equal ;ConsoleWrite($fhash & ":" & $dHash & " equal" & @CRLF) ;ConsoleWrite("File: " & $fhash & @CRLF & "Directory: " & $dHash & @CRLF & "equal: yes " & @CRLF) Else ;if compared hashes are not equal ;ConsoleWrite("File: " & $fhash & @CRLF & "Directory: " & $dHash & @CRLF & "equal: not " & @CRLF) ;MsgBox(0,"hash md5",$fhash & ":" & $dHash & " not equal") EndIf Next ;ConsoleWrite("hashes are equal" & @CRLF) $comparison_ok = true Else ConsoleWrite("number of files in monitoring dir are not same as recorded" & @CRLF) ConsoleWrite("directory: " & $dArray[0] &":"& "files: " & UBound($fArray) - 1 & @CRLF) EndIf Return $comparison_ok EndFunc #main if LoadTripwireDB() = true Then ConsoleWrite(" hashes are equal " & @CRLF) ElseIf LoadTripwireDB() <> true Then ConsoleWrite(" hashes are not equal " & @CRLF) ConsoleWrite(" hashes are not equal " & @CRLF) Initial() EndIf  
      tripwire.au3
      tripwire.txt
    • dascondor
      By dascondor
      So I having issues with this GUI/Listview. My main GUI works like it needs to but the ListView GUIs don't. The exit buttons do not work on them and om have a hard time getting them to work. And I'm trying to make the  listview GUI resizeable. But I'm not sure how to fix either of these issues any thoughts.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <ListviewConstants.au3> #include 'MultiPing.au3' Opt("GUIOnEventMode", 1) #Region ;Declares ; Reads text file for the base list of IP's Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt") Global $replace2 = "Second" Global $replace3 = "Thrid" ;Global $userdata1 = GUICtrlRead($data1) ;Global $userdata2 = GUICtrlRead($data2) Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" Global $1stpaths = "\~~~Store" Global $2ndpaths = "~~~" Global $results = FileExists($savefolder & @UserName & $paths) ;Global $foldercheck = FileExists($savefolder & @UserName & $paths & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) ;Global $savefile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" #EndRegion ;Declares #Region ### START Koda GUI section ### Form= $IPMonkey = GUICreate("IP Monkey", 573, 254, -1, -1) GUISetIcon("C:\Users\Dlex\Pictures\monkeyicon.ico", -1) GUISetFont(16, 800, 0, "Arial") GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $data1 = GUICtrlCreateInput("1", 184, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $data2 = GUICtrlCreateInput("23", 280, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $GOButton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetOnEvent(-1, "GOButtonClick") $quickscan = GUICtrlCreateButton("Quick Scan", 224, 192, 107, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetOnEvent(-1, "quickscanClick") GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") Global $exitbutton = GUICtrlCreateButton("Exit", 416, 192, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetOnEvent(-1, "exitbuttonClick") $titlebar = GUICtrlCreateLabel("IP Monkey", 16, 120, 107, 28) GUICtrlSetColor(-1, 0x000000) $Pic1 = GUICtrlCreatePic("C:\Users\Dlex\Pictures\monkeyicon-0.jpg", 16, 16, 100, 100) GUICtrlSetOnEvent(-1, "Pic1Click") $infobutton = GUICtrlCreateButton("?", 536, 8, 27, 25) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetOnEvent(-1, "infobuttonClick") $Whatstorelabel = GUICtrlCreateLabel("What Store?", 208, 56, 130, 28) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ;ping gui ; ------ pinger GUI ------------------- Global $StopPing = 0 Local $Win_X = 1200, $Win_Y = 880 ; dimension of window Global $PingGui = GUICreate("IP Monkey", $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) $button1 = GUICtrlCreateLabel("Hit Exit To Quit", 10, $Win_Y - 25, $Win_X - 20, 20, -1,$ES_CENTER) GUICtrlSetFont(-1, 10, 800) GUICtrlSetTip(-1, "exit") GUICtrlSetOnEvent(-1, 'SpecialEvents') GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) GUISetState(@SW_HIDE) ; hidden at startup ; --------- end of pinger gui ------------- #EndRegion ;ping gui ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) While 1 Sleep(100) WEnd Func exitbuttonClick() MsgBox(0,'0','0') Exit EndFunc ;==>exitbuttonClick Func GOButtonClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go EndFunc ;==>GOButtonClick Func infobuttonClick() EndFunc ;==>infobuttonClick Func Pic1Click() EndFunc ;==>Pic1Click Func quickscanClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) EndFunc ;==>quickscanClick Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE _button1() Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE EndSelect EndFunc ;==>SpecialEvents #Region ; Main_GO/Replace_and_GO #cs ############################## second script ############################################# ; this is to ping continuously a list of IP addresses, get and display ping result "live" ; it simulates the dos "ping -t" command but performed simultaneously on many IP ; presenting the results in a ListView highlighting not responding devices with a red box #ce Func replace_And_Go($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "exitbuttonClick") $StopPing = 0 ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's ; ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt ; values in the file should be separated by a semicolon, something like in the following example: ; ; hostname1;192.168.0.1 ; hostname2;192.168.0.5 ; hostnameX;10.59.7.200 ; etc.... ; ; if values in the file are not separated by a semicolon, but another char is used, for example a comma, ; then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",") ; _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_DeleteAllItems($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt) Sleep(10) ; ; $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case) ; | ; | 1 means the IP are in the second column of the $IPlist array (first colun is nr. 0) ; | | ; | | +--> 0 means return back an array loaded with results from all pinged addresses (responding and not responding) ; | | | if you use 1 then only responding addresses are loaded in the returned array [default] ; | | | if you use 2 then only NOT responding addresses are loaded in the returned array ; | | | In this case we do not need an array to be returned, we only need to perform all pings and pass results ; | | | directly (on the fly) to the "_refresh" callback function that will refresh the listview ; | | | ; | | | 0 means NO lookup name resolution must be performed ; | | | | ; | | | | +--> this is the callback function to be called for each pinged address each time the ping has finished ; | | | | | (see the MultiPing.au3 file for info on all passed params) ; | | | | | 6 parameters are passed to this function, but only 2 are used by the called function in this case: ; | | | | | [4] roundtrip of the responding ping or -1 if IP is down ; | | | | | [5] Index (position) of this IP within the caller's passed array ; | | | | | ; v v v v v _nPing($IPlist, 1, 0, 0, "_refresh") WEnd EndFunc ;==>Main_GO #EndRegion ; Main_GO/Replace_and_GO #Region ; QuickScan/Replace_and_GO2 Func replace_And_Go2($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go2 Func QuickRun($IPlist) $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) HotKeySet("{esc}", "_button1") Local $Win_X = 1200, $Win_Y = 880 ; dimension of window $PingGui = GUICreate("IP Monkey" & "~~~" & @UserName & "~~~" & "Store" & $userdata1 & $userdata2 & "~~~" & @MON & "." & @MDAY & "." & @YEAR & "~~~" & @HOUR & "." & @MIN, $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui) $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20) GUICtrlSetTip(-1, "End of program") GUICtrlSetOnEvent(-1, "exitbuttonClick") GUISetState(@SW_SHOW) ;~ $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) ;While 1 ; perform Pings and update ListView by the "_refresh" callback function $aFinalResult = _nPing($IPlist, 1, 0, 0, "_refresh") ;~ _ArrayDisplay($aFinalResult) ;DirCheck() EndFunc ;==>QuickRun #EndRegion ; QuickScan/Replace_and_GO2 #Region ; Misc Funcs (network) Func _refresh($Params) ; this receive ping results and displays them in the ListView _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow Sleep(50) ; a little wait If $Params[4] = -1 Then ; Device not responding to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item Else ; Device responds to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN EndIf EndFunc ;==>_refresh Func _button1() ; Button 1 clicked ;~ $StopPing = 1 Exit EndFunc ;==>_button1 #EndRegion ; Misc Funcs (network)  
      MultiPing.au3
      IP_List.txt
    • 5ervant
      By 5ervant
      What's the best way to receive file from a desktop app?
      app.exe will execute a cmd with "au3file.exe /path/of/the/file.xml" and the au3file.exe will get and delete that. Or else? THE MOST IMPORTANT PART OF THE QUESTION
      And best way to transfer file to a desktop app?
      au3file.exe do a $_POST request and the app.exe MUST HAVE a local HTTP server that can receive $_POST, but it looks heavy 'cause the app must have a server such XAMPP. au3file.exe execute a cmd with "app.exe /path/of/the/file.xml" and the app.exe will now get that file and delete. Or else?  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I'm working on this little project for a week, and, what I'm trying to do could be useful for many users as well...
      I'm trying to do a "Report Generator", which reads the data that have to report from a text file (.txt) formatted with this pattern;
      Data1;Data2;Data3;Data4;Data5;;

      YES, there are 2 semi-colon at the end of the line.

      In detail, Data1 is a date/time stamp with this format: YYYY/MM/DD HH:MM:SS ;

      When the script starts, the user is prompted to choose 2 dates which I'll call as:
      Report_Date_Start; Report_Date_Start. So, the report, should cover all dates between Report_Date_Start AND Report_Date_End.

      And, already at this point, I don't know how to do the query... How can I say to the script:
      SELECT * FROM (.txt) WHERE Data1 BETWEEN Report_Date_Start AND Report_Date_End; ?

      I thought that I could do a _DateDiff, but if the difference between the two dates is months and not days, how can I do the trick?
      Should I make a Switch...Case with the _DateDiff() and see then calculate all the dates between Report_Date_Start AND Report_Date_End... But then, how can I compare the dates in the file with all the dates between Report_Date_Start AND Report_Date_End? I'm going crazy, I know...

      I've already made a "Export Tool", which exports the content of the .txt file in a .db, managed with SQLite... I mean, there I could easily do a query like I did above the thread, but, this "export", for 1080 rows, takes 28 seconds to be done. And, 1080 rows are daily rows that are added every day in the .txt file, so, in a week, the file could be easily 7000+ rows, which means that the "export" would take 3 minutes to be done... And we can go over and over...
      I'll post just for be "complete" what I've done about the export, so, maybe, someone could say how to improve it in terms of efficency...
       
      Local $aContenutoFileAuditReport = "" _FileReadToArray($sFileAudit_Report, $aContenutoFileAuditReport) If(IsArray($aContenutoFileAuditReport) And Not @error) Then Local $aContenutoFileAuditReport_Splitted = "" Local $sQuery = "" Local $hInizioConteggio = TimerInit() For $i = 1 To UBound($aContenutoFileAuditReport) - 1 $aContenutoFileAuditReport_Splitted = StringSplit($aContenutoFileAuditReport[$i], ";") $sQuery = "INSERT INTO FileDB_Report(DATESTAMP, TIMESTAMP, USER_ID, OBJECT_ID, DESCRIPTION, COMMENT) " & _ "VALUES(" & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[0]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[1]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[3]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[4]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[5]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[6]) & ");" If(_SQLite_Exec($hFileDB_Report, $sQuery) <> $SQLITE_OK) Then ConsoleWrite("Errore durante l'esecuzione della query #" & $i & @CRLF) Else ConsoleWrite("Query eseguita correttamente #" & $i & @CRLF) EndIf Next ConsoleWrite("Esportazione completata in: " & Round(TimerDiff($hInizioConteggio)/1000, 0) & " secondi") Else MsgBox($MB_ICONERROR, "Errore!", "Errore durante la lettura del file nell'array." & @CRLF & "Errore: " & @error) EndIf I know that I can't do queries from a .txt file...
      [19:18] 
      I've been writing this post from 18:40 maybe...
      By the way, if @jchd or someone else could tell me if I can import a formatted .txt file in SQLite and then, do queries on the DB, I'd be very happy for that...
      About the report in PDF, I'm talking with @taietel in order to know how to create a PDF.
      I hope someone will help me
      Sorry for the "long" list of questions...
      Thank you for everything you've done for me
      I have to say that this is the community of programming language that I've loved most!
      By the way, I'll be back tomorrow in the morning ( ~ 9:15 a.m. Italian time ), so, excuse me if I can't answer before that time.
      Hope you guys have a wonderful day/night.

      Thanks again

      Francesco
    • ur
      By ur
      We can get a list of file using the below code.
      Local $aFileList = _FileListToArray(@DesktopDir, "*") Is there any option to use the above one recursively to get sub folders and their contents also.??
      And also, is there any way to serialize the above array locally to some file and load it later when we want in another program on another machine so that we can compare its contents with a folder in different machine, which is not network connected also.?