Jump to content
Sign in to follow this  
31290

File into list view and other

Recommended Posts

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

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:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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:

 


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi guys!, i have a problem to convert Python code to AutoIt code, in fact i had not coded with Python yet!, this code is about permutation a string's case, i will be happy with your comments :)❤;

      Python code:
       
      # Python code to print all permutations # with respect to cases # Function to generate permutations def permute(inp): n = len(inp) # Number of permutations is 2^n mx = 1 << n # Converting string to lower case inp = inp.lower() # Using all subsequences and permuting them for i in range(mx): # If j-th bit is set, we convert it to upper case combination = [k for k in inp] for j in range(n): if (((i >> j) & 1) == 1): combination[j] = inp[j].upper() temp = "" # Printing current combination for i in combination: temp += i print(temp), # Driver code permute("Hello") # This code is contributed by Sachin Bisht
      My code in AutoIt:
      ; https://www.geeksforgeeks.org/permute-string-changing-case/ _PermuteCase("ABC") Func _PermuteCase($sText) If StringRegExp($sText, "^[A-Za-z]{1,}$") Then Local $iLength = StringLen($sText) ; Get length of the text. Local $iMaxPerm = 2 ^ $iLength ; Number of permutations is 2^n Local $sLow_Text = StringLower($sText) ; Converting string to lower case Local $asChrs = StringToASCIIArray($sLow_Text) ; Split the text into array of chars. For $i = 1 To $iMaxPerm Step 1 For $j = 0 To $asChrs[0] ;................................................... Next Next Else Return SetError(-1, 0, "Error: Input is incorrect!") EndIf EndFunc ;==>_PermuteCase  
       
       
       
       
       
      ====================== SOLUTION by @TheXman ======================
       
    • By ThePoro
      Hello,
      I have a problem with getting first 10 characters with a big txt file, about 50k lines. I only want 10 characters of each line and save it into another file. I tried to use Stringleft every line and save it into another file but it was really slow to do it. I tried to save it into a variation like $var=$var&stringleft($file,10)&@CRLF. It's faster but still really slow.
      Can anybody help me with this
      Thank you so much
    • By Scriptmaster
      <NEWBIE ALERT>
      Is it possible to unzip a zip file in Autoit without using a dll!
      My script downloads a zip file to a temporary directory (successfully) and it must be unzipped to (Or moved to after unzip) another a folder which just happens to be
      @scriptdir & "file.exe" Thanks in advance
    • By Inpho
      Hi All,
      I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free.
      String functions:
      #AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, $bHumanFormat = False]) ; Parameters ....: $iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; $bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet($iType = 1, $bHumanFormat = False) If $iType < 1 Or $iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local $sTime = @HOUR & ":" & @MIN & ":" & @SEC Local $sDate = @MDAY & "/" & @MON & "/" & @YEAR If $iType = 1 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, ":", "") $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) Return ($sDate & "_" & $sTime) Else Return ($sDate & " " & $sTime) EndIf ElseIf $iType = 2 Then If $bHumanFormat = False Then $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) EndIf Return ($sDate) ElseIf $iType = 3 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, "/", "") EndIf Return ($sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension($sPath) Return (StringTrimLeft($sPath, StringInStr($sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName($sPath[, $bIncludeExtension = True]) ; Parameters ....: $sPath - a string value. ; $bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName($sPath, $bIncludeExtension = True) Local $sReturn = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) If $bIncludeExtension = False Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, ".", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath($sPath) Return (StringLeft($sPath, StringInStr($sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom($iAmount[, $iType = 1]) ; Parameters ....: $iAmount - an integer value. Length of returned string ; $iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - $iAmount is not a positive integer ; 2 - $iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom($iAmount, $iType = 1) If $iAmount < 1 Or IsInt($iAmount) = 0 Then Return (SetError(-1, 0, "")) Local $sString = "" Local $iRandomLow = 1, $iRandomHigh = 62 #Tidy_Off Local Static $aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If $iType = 1 Then ;; digits: 1 - 10 $iRandomHigh = 10 ElseIf $iType = 2 Then ;; hexadecimal: 1 - 16 $iRandomHigh = 16 ElseIf $iType = 3 Then ;; alnumupper: 1 - 36 $iRandomHigh = 36 ElseIf $iType = 4 Then ;; alnum: 1 - 62 $iRandomHigh = 62 ElseIf $iType = 5 Then ;; alphaupper: 11 - 36 $iRandomLow = 11 $iRandomHigh = 36 ElseIf $iType = 6 Then ;; alpha: 11 = 62 $iRandomLow = 11 $iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For $i = 1 To $iAmount $sString &= $aCharId[Random($iRandomLow, $iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return ($sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples:
      ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)  
    • By TheAutomator
      I'm working on a script that needs to work with a huge database inside a combobox.
      I'm looking for the best way to link a multidimensional array to that data to load that data on to textfields.

      example:
      combo item 0 = "A", data = [index linked to combo item 0] [1,0,5,4,87,9,"xyz"]
      combo item 1 = "B", data = [index linked to combo item 1] [1,6,5,4,87,9,"zzz"]
      combo item 3 = "A", data = [index linked to combo item 3] [1,6,4,4,87,9,"aaa"] ; yes also double items!
      Would also like to be able to delete and add items on the fly btw..
      Local $INDEX[0][10] ; ubound wil be resized like a stack while loading from a textfile ;inside gui: local $Combo = GUICtrlCreateCombo('...', 10, 10, 290, 25) ;gui loop: While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Combo display() ; how do i link my array index to the combo labels to know what to show in the textfields? ; NOTE: (there are duplicate items in the combobox!) EndSwitch WEnd Any toughs are welcome.
      I was thinking about using _GUICtrlComboBox_GetCurSel($Combo) and use that integer to refer to the index (dimension 1) of the array 
      Thanks, TheAutomator
       
×
×
  • Create New...