Jump to content

Recommended Posts

Posted (edited)

Hello everyone,

Earlier i was having trouble with a script and Smashly made me a lovely script which did what i wanted to, now comes the fact that i want to combine it in to the script that i'm using, tho it would be nearly impossible to have anyone else run the script like i do, i try to cut out the 2 pieces that i need to make work together.

Smashly's script

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#Include <File.au3>

Opt('MustDeclareVars', 1)

_Main()
If @error Then MsgBox(64, "Error", "No txt file found")


Func _Main()
    ;Set this to the path of yoor large text file
    Local $sTextFile = @ScriptDir & "\LargeTextfile.txt"
    Local  $aText, $hListView

    ;Read the txt file to an array
    If Not _FileReadToArray($sTextFile, $aText) Then Return SetError(1, 0, 0)
    
    ; Dim a 2D $aLV_Text array based on how many items are in the $aText array
    ; We use this array later to add it to the listview.
    Dim $aLV_Text[$aText[0]][1]
    
    ; Loop through the $aText array 
    For $i = 1 To $aText[0]
        
        ; String Split each line at the comma
        Local $aSSL = StringSplit($aText[$i], ",")

        ; See if we need more collomns in out listview
        If $aSSL[0] > Ubound($aLV_Text, 2) Then ReDim $aLV_Text[$aText[0]][$aSSL[0]]

        ;Loop through the Split line and add the new broken up line to $aLV_Text array.
        For $j = 0 To Ubound($aLV_Text, 2) - 1
            $aLV_Text[$i - 1][$j] = $aSSL[$j + 1]
        Next
    Next


    ; Create GUI
    GUICreate("ListView Add Array", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    _GUICtrlListView_SetUnicodeFormat($hListView, False)
    GUISetState()

    ; Add columns based on how many subitems are in a line
    For $i = 0 To Ubound($aLV_Text, 2) - 1
        If Not $i Then _GUICtrlListView_AddColumn($hListView, "Items ", 100)
        If $i Then _GUICtrlListView_AddColumn($hListView, "SubItems " & $i, 100)
    Next


    ;Set the listview item count based on how many items in the $aLV_Text array, saves the listview calculating structures with every item added
    _GUICtrlListView_SetItemCount($hListView, Ubound($aLV_Text, 1))

    ; Load $aLV_Text array to the listview
    _GUICtrlListView_AddArray($hListView, $aLV_Text)


    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

here is the file called "LargeTextfile.txt"

2011-03-16 11:04:14, Bo Munch Jensen (bmj), \\fs6\privat$\Ansatte\bmj (\\fs6\privat$\Ansatte\bmj), M11550, 10.253.3.12 - fe80::fdb3:c259:4bdb:ab25 & 10.232.28.50 - fe80::a812:82fa:11de:e4c7
2011-03-16 11:04:53, Joan Pape Rasmussen (jpr), \\eamv-fs1\Privat$\Ansatte\jpr (\\eamv-fs1\Privat$\Ansatte\jpr), M11384, 0.0.0.0 & 10.153.236.90
2011-03-16 11:05:07, John Martin Jørgensen (jmj), \\fs6\privat$\Ansatte\jmj (\\fs6\privat$\Ansatte\jmj), S07834, 10.253.3.12
2011-03-16 11:07:00, 76006 (76006), \\fs2\home$\Studerende\76006 (\\fs2\home$\Studerende\76006), S09482, 10.27.1.17
2011-03-16 11:07:19, Steen Juul Mortensen (sjm), \\fs6\privat$\Ansatte\sjm (\\fs6\privat$\Ansatte\sjm), S09233, 10.62.200.42
2011-03-16 11:09:58, 78747 (78747), \\fs2\home$\studerende\78747 (\\fs2\home$\studerende\78747), S09482, 10.27.1.17
2011-03-16 11:13:13, 76006 (76006), \\fs2\home$\Studerende\76006 (\\fs2\home$\Studerende\76006), S10205, 10.27.1.12
2011-03-16 11:15:30, 60867 (60867), \\fs2\home$\Studerende\60867 (\\fs2\home$\Studerende\60867), M09126, 10.232.44.25 & 0.0.0.0 & 10.232.44.25
2011-03-16 11:15:42, Leif Kloster (lk), \\fs6\privat$\Ansatte\lk (\\fs6\privat$\Ansatte\lk), M09087, 10.5.1.10 & 10.232.32.164
2011-03-16 11:16:53, 43146 (43146), \\fs2\home$\Studerende\43146 (\\fs2\home$\Studerende\43146), S09159, 10.38.1.22
2011-03-16 11:17:14, 103086 (103086), \\fs2\home$\Studerende\103086 (\\fs2\home$\Studerende\103086), S06525, 10.80.4.114 - fe80::34a3:2f03:c4f8:3672
2011-03-16 11:19:48, Lilian Lodal Christensen (llc), \\fs6\privat$\Ansatte\llc (\\fs6\privat$\Ansatte\llc), S07631, 10.8.1.27
2011-03-16 11:21:28, Jens Peter Stou (jps), \\fs6\privat$\Ansatte\jps (\\fs6\privat$\Ansatte\jps), M09197, 0.0.0.0 & 10.232.16.103
2011-03-16 11:22:11, 100379 (100379), \\fs2\home$\Studerende\100379 (\\fs2\home$\Studerende\100379), S07284, 10.12.1.22
2011-03-16 11:27:04, supporten (supporten), \\fs2\home$\IT-administratorer\supporten (\\fs2\home$\IT-administratorer\supporten), M07948, 10.253.3.11 & 0.0.0.0
2011-03-16 11:25:19, 97901 (97901), \\fs2\home$\Studerende\97901 (\\fs2\home$\Studerende\97901), S07895, 10.8.1.25
2011-03-16 11:26:15, Carsten Nielsen (cni), \\fs6\privat$\Ansatte\cni (\\fs6\privat$\Ansatte\cni), S09233, 10.62.200.42
2011-03-16 11:28:09, 78923 (78923), \\fs2\home$\studerende\78923 (\\fs2\home$\studerende\78923), S11603, 10.29.1.14 - fe80::252b:4ec8:15cd:6095
2011-03-16 11:28:36, Pia Brændgaard (pb), \\fs6\privat$\Ansatte\pb (\\fs6\privat$\Ansatte\pb), M10108, 10.232.40.130 - fe80::852c:89ea:67b:2ec
2011-03-16 11:29:02, Bodil Carstensen (bca), \\eamv-fs1\Privat$\Ansatte\bca (\\eamv-fs1\Privat$\Ansatte\bca), M07933, 0.0.0.0 & 10.153.244.91 & 10.153.244.91
2011-03-16 11:32:54, Gisela Hansen (gih), \\fs6\privat$\Ansatte\gih (\\fs6\privat$\Ansatte\gih), S06715, 10.80.4.51 - fe80::40f4:a7c6:16e2:870
2011-03-16 11:33:35, Leif Peder Møller (lm), \\fs6\privat$\Ansatte\lm (\\fs6\privat$\Ansatte\lm), M00154, 0.0.0.0 & 10.232.28.82
2011-03-16 11:34:37, Finn Christensen (fc), \\fs6\privat$\Ansatte\fc (\\fs6\privat$\Ansatte\fc), M11485, 10.232.32.165 - fe80::214a:39d7:a581:a091
2011-03-16 11:35:42, Niels Peter Jørgensen (npj), \\fs6\privat$\Ansatte\npj (\\fs6\privat$\Ansatte\npj), M0-NPJ, 10.60.200.18 - fe80::a90e:2319:c505:f304 & 10.153.236.91 - fe80::5939:75f8:cbcd:d2ad & 169.254.64.162 - fe80::e90a:c102:5806:40a2 & 192.168.224.1 - fe80::21a4:82d7:fa6b:285c
2011-03-16 11:36:43, Claus Gam-Pedersen (cg), \\fs6\privat$\Ansatte\cg (\\fs6\privat$\Ansatte\cg), S06675, 10.80.4.56 - fe80::446f:6206:f4ae:3281
2011-03-16 11:36:54, Bo Munch Jensen (bmj), \\fs6\privat$\Ansatte\bmj (\\fs6\privat$\Ansatte\bmj), M11550, 10.253.3.12 - fe80::fdb3:c259:4bdb:ab25
2011-03-16 11:39:36, 67536 (67536), \\fs2\home$\Studerende\67536 (\\fs2\home$\Studerende\67536), S09160, 10.38.1.12
2011-03-16 11:39:51, Bo Munch Jensen (bmj), \\fs6\privat$\Ansatte\bmj (\\fs6\privat$\Ansatte\bmj), M11550, 10.253.3.12 - fe80::fdb3:c259:4bdb:ab25
2011-03-16 11:42:48, 90233 (90233), \\fs2\home$\studerende\90233 (\\fs2\home$\studerende\90233), S06545, 10.80.2.31 - fe80::78f5:c6e8:64bc:9a93
2011-03-16 11:44:21, Carsten Nielsen (cni), \\fs6\privat$\Ansatte\cni (\\fs6\privat$\Ansatte\cni), S09233, 10.62.200.42
2011-03-16 11:44:33, Morten Østerby Andreasen (moa), \\fs6\privat$\Ansatte\moa (\\fs6\privat$\Ansatte\moa), M10189, 10.232.12.94 - fe80::4129:7cc4:9e39:69fb

And here is the script part of the script that i've tried to merge it together with (made by Melba23)

$iEnd = UBound($File) - 1
                    $Noftimes = 0
            Do
                ; Look for a line containing $User
                $iIndex = _ArraySearch($File, "\" & $User & " ", 0, $iEnd, 0, 1, 0)
                ; If we found one then add it to the List
                If Not ($iIndex = -1) Then
                $sLine = $File[$iIndex]
                ; Now format it as we require
                $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, ".int", ".int -")
                $sLine = StringReplace($sLine, "(\\fs6", ",\\fs6")
                $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
                $sLine = StringReplace($sLine, ")", "") ; remove the final )
                ; Now add to the List contents
                $sList &= "," & $sLine & ",|"
                ; Amend the last search element
                $iEnd = $iIndex - 1
                ; if we have reached the top line then exit the search
                If $iEnd = 0 Then ExitLoop
                ; Increase the count
                $Noftimes += 1
                Else
                ; If we found nothing then exit the search
                ExitLoop
                EndIf
                Until $Noftimes = 15

and finaly my failed attempt

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#Include <File.au3>
#Include <Array.au3>

;Opt('MustDeclareVars', 1)

_Main()



Func _Main()
    ;Set this to the path of yoor large text file
    Local $sTextFile = @ScriptDir & "\LargeTextfile.txt"
    Local  $aText, $hListView, $File, $sList, $Noftimes
    local $User = "bmj"

            If Not _FileReadToArray($LogFile, $File) Then
                MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
            Exit
        EndIf
                    $iEnd = UBound($File) - 1
                    $Noftimes = 0
            Do
                ; Look for a line containing $User
                $iIndex = _ArraySearch($File, "\" & $User & " ", 0, $iEnd, 0, 1, 0)
                ; If we found one then add it to the List
                If Not ($iIndex = -1) Then
                $sLine = $File[$iIndex]
                ; Now format it as we require
                $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, ".int", ".int -")
                $sLine = StringReplace($sLine, "(\\fs6", ",\\fs6")
                $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
                $sLine = StringReplace($sLine, ")", "") ; remove the final )
                ; Now add to the List contents
                $sList &= "," & $sLine & ",|"
                ; Amend the last search element
                $iEnd = $iIndex - 1
                ; if we have reached the top line then exit the search
                If $iEnd = 0 Then ExitLoop
                ; Increase the count
                $Noftimes += 1
                Else
                ; If we found nothing then exit the search
                ExitLoop
                EndIf
                Until $Noftimes = 15

;here is my problem, i can't translate my top result in to something i can use in the bottom half of the script         

                _ArrayAdd($aText, $sList)
                _ArrayDisplay($aText, "is array?")
                MsgBox(4096, "is string?", $sList)
    ; Dim a 2D $aLV_Text array based on how many items are in the $aText array
    ; We use this array later to add it to the listview.
    Dim $aLV_Text[$aText[0]][1]
    
    ; Loop through the $aText array 
      For $i = 1 To $aText[0]   
        ; String Split each line at the comma
        Local $aSSL = StringSplit($aText[$i], ",")

        ; See if we need more collomns in out listview
        If $aSSL[0] > Ubound($aLV_Text, 2) Then ReDim $aLV_Text[$aText[0]][$aSSL[0]]

        ;Loop through the Split line and add the new broken up line to $aLV_Text array.
        For $j = 0 To Ubound($aLV_Text, 2) - 1
            $aLV_Text[$i - 1][$j] = $aSSL[$j + 1]
        Next
    Next


    ; Create GUI
    GUICreate("ListView Add Array", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    _GUICtrlListView_SetUnicodeFormat($hListView, False)
    GUISetState()

    ; Add columns based on how many subitems are in a line
    For $i = 0 To Ubound($aLV_Text, 2) - 1
        If Not $i Then _GUICtrlListView_AddColumn($hListView, "Items ", 100)
        If $i Then _GUICtrlListView_AddColumn($hListView, "SubItems " & $i, 100)
    Next


    ;Set the listview item count based on how many items in the $aLV_Text array, saves the listview calculating structures with every item added
    _GUICtrlListView_SetItemCount($hListView, Ubound($aLV_Text, 1))

    ; Load $aLV_Text array to the listview
    _GUICtrlListView_AddArray($hListView, $aLV_Text)


    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
Edited by CartoonDragon
  • Moderators
Posted

Cartoondragon,

I only vaguely remember helping you with that script. And having 2 completely unrelated sections does not give much of hint as to what the desired output is supposed to be. :)

You obviously want to parse the file and display it in a ListView. So I suggest you take one line of the file and show which parts you want in each column of the ListView - that way we have a fighting chance to help you! :)

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

 

Posted (edited)

Hey Melba32,

I'm sorry for being so confusing, the results i'm trying to get is to turn a file filled with lines like this:

2011-03-16 11:04:14, Bo Munch Jensen (bmj), \\fs6\privat$\Ansatte\bmj (\\fs6\privat$\Ansatte\bmj), M11550, 10.253.3.12 - fe80::fdb3:c259:4bdb:ab25 & 10.232.28.50 - fe80::a812:82fa:11de:e4c7

in to a nice output in a listview with coloms and edit out the parts that i don't want and put it in a gui interface, listed up like this:

|         Time       |     Name             |     Initials        |      Network Drive       | Computer name   | Ip Address 1   | Ip Address 2  | 
2011-03-16 11:04:14   Bo Munch Jensen        bmj                   \\fs6\privat$\Ansatte\bmj   M11550           10.253.3.12      10.232.28.50

Having listet only the initials i've searched for, in this case bmj, and show the last 15 entries of his username matched to the computers he's been logged on to with the newest entry at the top showing 15 lines.

i was trying my best not to have to re-invent all the differnt parts my script is made up in to, thats why i added the confusment of files to see if i couldn't simply add a connection between the two, because the two scripts put together would do this function.

any help would be very much apprisiated

Edited by CartoonDragon
  • Moderators
Posted

Cartoondragon,

If you transfer the data directly from the file to the ListView, it is much easier: :)

#include <GUIConstantsEx.au3>
#include <File.au3>
#Include <GuiListView.au3>

Global $aFile, $aLine
Global $sInputFile = "Data.txt"

; Read in file
_FileReadToArray($sInputFile, $aFile)

; Create GUI
$hGUI = GUICreate("Test", 1000, 500)

$hListView = GUICtrlCreateListView(" DTG| Name| Initials| Network Drive| Computer| Ip Address 1| Ip Address 2| Ip Address 3| Ip Address 4", _
            10, 10, 980, 400)
_GUICtrlListView_SetColumnWidth($hListView, 0, 120)
_GUICtrlListView_SetColumnWidth($hListView, 1, 100)
_GUICtrlListView_SetColumnWidth($hListView, 2, 75)
_GUICtrlListView_SetColumnWidth($hListView, 3, 190)
_GUICtrlListView_SetColumnWidth($hListView, 4, 80)
_GUICtrlListView_SetColumnWidth($hListView, 5, 85)
_GUICtrlListView_SetColumnWidth($hListView, 6, 85)
_GUICtrlListView_SetColumnWidth($hListView, 7, 85)
_GUICtrlListView_SetColumnWidth($hListView, 8, 85)

$hInput = GUICtrlCreateInput("", 10, 430, 200, 20)

$hButton = GUICtrlCreateButton("Search", 10, 460, 80, 30)

$hLabel = GUICtrlCreateLabel("", 100, 465, 200, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sInits = GUICtrlRead($hInput)
            If $sInits Then
                _Display($sInits)
            EndIf
    EndSwitch

WEnd

Func _Display($sInits)

    ; I seem to remember you only wanted the final few records for an individual
    $iCount = 0

    ; Work through file from bottom to top
    For $i = $aFile[0] To 1 Step -1

        ; Split the line into its separate components
        $aLine = StringSplit($aFile[$i], ",", 2)

        ; Check if the initals match the search
        If StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") = $sInits Then

            ; Build up the items in the line to fill the ListView
            $sItems =   $aLine[0] & "|" & _
                        StringRegExpReplace($aLine[1], "(.*)\s\(.+\)", "$1") & "|" & _
                        StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") & "|" & _
                        StringRegExpReplace($aLine[2], "(.*)\s\(.+\)", "$1") & "|" & _
                        $aLine[3] & "|"

            $aIPs = StringRegExp($aLine[4], "(\d+\.\d+\.\d+\.\d+)", 3)
            For $j = 0 To UBound($aIPs) - 1
                $sItems &= $aIPs[$j] & "|"
            Next

            ; Increase the count
            $iCount += 1
            ; If below the limit you want to display then display it
            If $iCount < 6 Then GUICtrlCreateListViewItem($sItems, $hListView)

        EndIf

    Next

    ; Mention how many were actually found
    GUICtrlSetData($hLabel, "Total " & $iCount & " records found")

EndFunc

Please ask if you have any questions. :)

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

 

Posted

Hello everyone, seems like i managed to get it done, just needed to look more at what i was doing.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#Include <File.au3>
#Include <Array.au3>

;Opt('MustDeclareVars', 1)

_Main()



Func _Main()
    ;Set this to the path of yoor large text file
    Local $sTextFile = @ScriptDir & "\LargeTextfile.txt"
    Local  $aText, $hListView, $File, $sList, $Noftimes
    local $User = "bmj"

            If Not _FileReadToArray($sTextFile, $File) Then
                MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
            Exit
        EndIf
                    $iEnd = UBound($File) - 1
                    $Noftimes = 0
            Do
                ; Look for a line containing $User
                $iIndex = _ArraySearch($File, "\" & $User & " ", 0, $iEnd, 0, 1, 0)
                ; If we found one then add it to the List
                If Not ($iIndex = -1) Then
                $sLine = $File[$iIndex]
                ; Now format it as we require
                $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\IT-ADM~1\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\fs2\home$\STUDER~1\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\eamv-fs1\Privat$\Ansatte\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, "Homedir: \\fs6\privat$\Ansatte\", "") ; get rid of the path info
                $sLine = StringReplace($sLine, ".int", ".int -")
                $sLine = StringReplace($sLine, "(\\fs6", ",\\fs6")
                $sLine = StringReplace($sLine, "(", "- ") ; change the opening ( into -
                $sLine = StringReplace($sLine, ")", "") ; remove the final )
                ; Now add to the List contents
                $sList &= $sLine ;& "|"
                ; Amend the last search element
                $iEnd = $iIndex - 1
                ; if we have reached the top line then exit the search
                If $iEnd = 0 Then ExitLoop
                ; Increase the count
                $Noftimes += 1
                Else
                ; If we found nothing then exit the search
                ExitLoop
                EndIf
                $sList = $sList & "|"
                Until $Noftimes = 15

;here is my problem, i can't translate my top result in to something i can use in the bottom half of the script         

              $aText = StringSplit($sList, "|")
                _ArrayDisplay($aText, "is array?")
                MsgBox(4096, "is string?", $sList)
    ; Dim a 2D $aLV_Text array based on how many items are in the $aText array
    ; We use this array later to add it to the listview.
    Dim $aLV_Text[$aText[0]][1]
    
    ; Loop through the $aText array 
      For $i = 1 To $aText[0]   
        ; String Split each line at the comma
        Local $aSSL = StringSplit($aText[$i], ",")
                ;_ArrayDisplay($aSSL, "is array2?")

        ; See if we need more collomns in out listview
        If $aSSL[0] > Ubound($aLV_Text, 2) Then ReDim $aLV_Text[$aText[0]][$aSSL[0]]

        ;Loop through the Split line and add the new broken up line to $aLV_Text array.
        For $j = 0 To Ubound($aLV_Text, 2) - 1
            $aLV_Text[$i - 1][$j] = $aSSL[$j + 1]
        Next
    Next


    ; Create GUI
    GUICreate("ListView Add Array", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    _GUICtrlListView_SetUnicodeFormat($hListView, False)
    GUISetState()

    ; Add columns based on how many subitems are in a line
    For $i = 0 To Ubound($aLV_Text, 2) - 1
        If Not $i Then _GUICtrlListView_AddColumn($hListView, "Items ", 100)
        If $i Then _GUICtrlListView_AddColumn($hListView, "SubItems " & $i, 100)
    Next


    ;Set the listview item count based on how many items in the $aLV_Text array, saves the listview calculating structures with every item added
    _GUICtrlListView_SetItemCount($hListView, Ubound($aLV_Text, 1))

    ; Load $aLV_Text array to the listview
    _GUICtrlListView_AddArray($hListView, $aLV_Text)


    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
  • Moderators
Posted

Cartoondragon,

Glad you like it. :)

No questions - I must be getting better! :)

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

 

Posted

I know you don't like RegEx but this will do it too and it's shorter code

$sStr = "2011-03-16 11:04:14, Bo Munch Jensen (bmj), \\fs6\privat$\Ansatte\bmj (\\fs6\privat$\Ansatte\bmj), M11550, 10.253.3.12 - fe80::fdb3:c259:4bdb:ab25 & 10.232.28.50 - fe80::a812:82fa:11de:e4c7" & @CRLF
$sStr &= "2011-03-16 11:28:14, My Name (mn), \\fs6\privat$\Ansatte\gg(\\fs6\privat$\Ansatte\mn), M12050, 194.168.3.12 - fe80::fdb3:c259:4bdb:ab25 & 168.232.55.50 - fe80::a812:82fa:11de:e4c7" & @CRLF
$sStr &= "2011-03-15 09:52:08, Someone Else (se), \\fs6\privat$\Ansatte\se(\\fs6\privat$\Ansatte\se), R22050, 10.168.3.18 - fe80::fdb3:c259:4bdb:ab25 & 10.232.110.10 - fe80::a812:82fa:11de:e4c7"
;; $sStr above can be replaced ith a FileRead() call
;; In The regex replace below we just replace the parts we don't want with "|" which is the default separater for a listview.
;; The RegEx itself just reads each line (after the replace is done) to an array.  We can then just loop through the array to create the LVitems. I nested them but that isn't really required.
$aData = StringRegExp(StringRegExpReplace($sStr, "(?i)(?m:^)(.+),([\w\s]+)\s*\(([a-z]+)\),.+?\((.+?)\),\s*([a-z0-9]+),\s*([\d.]+).+&\s*([\d.]+)\V*", "$1|$2|$3|$4|$5|$6|$7"), "(?m:^)\V+", 3)
If NOT @Error Then
    GUICreate("Test Window", 600, 400)
    $hListview = GUICtrlCreateListView("Time|Name|Initials|Network Drive|Computer Name|IP Address|IP Address 2", 10, 10, 580, 350)
    For $i = 0 To UBound($aData) - 1
        GUICtrlCreateListViewItem($aData[$i], $hListview)
    Next

    GUISetState()
    While 1
        If GUIGetMsg() = -3 Then Exit
    WEnd
EndIf

Of course it can be tuned up with proper sizes and column widths etc.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted (edited)

Hey Melba23

i finaly got around to find something that doesn't work for me, i used your script on my log file (huuuuuge log file 10mb size) and then your script will crash. (that said i know my log file from time to time have som inconsistancies, but i don't see what would do this to it)

S:\Scripts\User Checker\melba23.au3 (66) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") = $sInits Then

If StringRegExpReplace(^ ERROR

it outputs data like it's suppose to, but then after 4-5 seconds the program dies and crashes

seemingly the error to me is that it wants to do this function to all of the of the logfile? while i simply want it to do it to the 15 outputs that i want to see

Edited by CartoonDragon
  • Moderators
Posted

Cartoondragon,

it wants to do this function to all of the of the logfile? while i simply want it to do it to the 15 outputs that i want to see

How do you expect it to extract the lines you want to see if it does not run through all the lines in the file? :) The line in question extracts the lines of data with the initials you are searching for.

The error means that the line could not be parsed. So you need to do one of two things:

- 1. Ignore the line. Then you need to change the function like this: :P

Func _Display($sInits)

    ; I seem to remember you only wanted the final few records for an individual
    $iCount = 0

    ; Work through file from bottom to top
    For $i = $aFile[0] To 1 Step -1

        ; Split the line into its separate components
        $aLine = StringSplit($aFile[$i], ",", 2)
        If Not @error Then 

            ; Check if the initals match the search
            If StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") = $sInits Then

                ; Build up the items in the line to fill the ListView
                $sItems =   $aLine[0] & "|" & _
                            StringRegExpReplace($aLine[1], "(.*)\s\(.+\)", "$1") & "|" & _
                            StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") & "|" & _
                            StringRegExpReplace($aLine[2], "(.*)\s\(.+\)", "$1") & "|" & _
                            $aLine[3] & "|"

                $aIPs = StringRegExp($aLine[4], "(\d+\.\d+\.\d+\.\d+)", 3)
                For $j = 0 To UBound($aIPs) - 1
                    $sItems &= $aIPs[$j] & "|"
                Next

                ; Increase the count
                $iCount += 1
                ; If below the limit you want to display then display it
                If $iCount < 6 Then GUICtrlCreateListViewItem($sItems, $hListView)

            EndIf
        
        EndIf

    Next

    ; Mention how many were actually found
    GUICtrlSetData($hLabel, "Total " & $iCount & " records found")

EndFunc

- 2. Fix your log file so it does not contain lines which cannot be parsed. :)

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

 

Posted

Hey Melba23

i ended up going with option 2, need to go kick some guy at work tomorrow for putting in "sdfsdfsdfsdfsdf" (empty line) "sdfsdfsdfsdfsdf" in the middle of my log file, tested the new script you postet, worked like a charm ^^ thanks a lot Melba23 you really have a lot of patience.

Posted

Hello Everyone,

Trying to re-use Melba23's script to now search for the computer name in the program insted of username, but i belive it's an easy fix, but it didn't quite work like i thought it would. Changing the latest script by Melba23 to look like this but doesn't work.

Func _Display($sInits)

    ; I seem to remember you only wanted the final few records for an individual
    $iCount = 0

    ; Work through file from bottom to top
    For $i = $aFile[0] To 1 Step -1

        ; Split the line into its separate components
        $aLine = StringSplit($aFile[$i], ",", 2)
        If Not @error Then 

            ; Check if the initals match the search
;----------------------------------The only change in the script------------------
            ;If StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") = $sInits Then

             If $aLine[3] = $sInits Then
;----------------------------------Change complet---------------------------------

                ; Build up the items in the line to fill the ListView
                $sItems =   $aLine[0] & "|" & _
                            StringRegExpReplace($aLine[1], "(.*)\s\(.+\)", "$1") & "|" & _
                            StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") & "|" & _
                            StringRegExpReplace($aLine[2], "(.*)\s\(.+\)", "$1") & "|" & _
                            $aLine[3] & "|"

                $aIPs = StringRegExp($aLine[4], "(\d+\.\d+\.\d+\.\d+)", 3)
                For $j = 0 To UBound($aIPs) - 1
                    $sItems &= $aIPs[$j] & "|"
                Next

                ; Increase the count
                $iCount += 1
                ; If below the limit you want to display then display it
                If $iCount < 6 Then GUICtrlCreateListViewItem($sItems, $hListView)

            EndIf
        
        EndIf

    Next

    ; Mention how many were actually found
    GUICtrlSetData($hLabel, "Total " & $iCount & " records found")

EndFunc

now in my mind, $aLine[3] = the computer name from my list, but it's in array format and i need it in a string, any good ideas?

Posted

Hello Everyone,

Trying to re-use Melba23's script to now search for the computer name in the program insted of username, but i belive it's an easy fix, but it didn't quite work like i thought it would. Changing the latest script by Melba23 to look like this but doesn't work.

Func _Display($sInits)

    ; I seem to remember you only wanted the final few records for an individual
    $iCount = 0

    ; Work through file from bottom to top
    For $i = $aFile[0] To 1 Step -1

        ; Split the line into its separate components
        $aLine = StringSplit($aFile[$i], ",", 2)
        If Not @error Then 

            ; Check if the initals match the search
;----------------------------------The only change in the script------------------
            ;If StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") = $sInits Then

             If $aLine[3] = $sInits Then
;----------------------------------Change complet---------------------------------

                ; Build up the items in the line to fill the ListView
                $sItems =   $aLine[0] & "|" & _
                            StringRegExpReplace($aLine[1], "(.*)\s\(.+\)", "$1") & "|" & _
                            StringRegExpReplace($aLine[1], ".*\s\((.+)\)", "$1") & "|" & _
                            StringRegExpReplace($aLine[2], "(.*)\s\(.+\)", "$1") & "|" & _
                            $aLine[3] & "|"

                $aIPs = StringRegExp($aLine[4], "(\d+\.\d+\.\d+\.\d+)", 3)
                For $j = 0 To UBound($aIPs) - 1
                    $sItems &= $aIPs[$j] & "|"
                Next

                ; Increase the count
                $iCount += 1
                ; If below the limit you want to display then display it
                If $iCount < 6 Then GUICtrlCreateListViewItem($sItems, $hListView)

            EndIf
        
        EndIf

    Next

    ; Mention how many were actually found
    GUICtrlSetData($hLabel, "Total " & $iCount & " records found")

EndFunc

now in my mind, $aLine[3] = the computer name from my list, but it's in array format and i need it in a string, any good ideas?

Yep, figured out there was a single empty space infront of the text in $aLine[3]
  • Moderators
Posted

Cartoondragon,

StringStripWS might be useful then. :)

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

 

Posted (edited)

Melba23,

sorry to bother again for such a simple thing, but i was thinking that you know a smart way of doing this, i'm using the following command to load my logfile in to my script:

If Not _FileReadToArray($LogFile, $aFile) Then

MsgBox(4096, "Error", " Error reading log to Array error:" & @error)

Exit

EndIf

But i want to put it in a function, so if it's already loaded in to the script, not to do it again, because i don't want it to read the logfile untill i push the button the first time, to save the initial load time, because i need to load 3 log files all in all.

Edited by CartoonDragon
  • Moderators
Posted

Cartoondragon,

The correct decision - keep SREs until you really need them. :)

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

 

Posted

Melba23,

now that was a quick responce, but uhm... sorry but how would you make such a function to see if it has already been loaded, i thought i could check if there was something in $aFile with a simple command, like so:

if $aFile Then

MsgBox(4096, "$aFile true?", "Yes")

Else

MsgBox(4096, "$aFile true?", "No")

EndIf

but the answer is always no, the only other thing i can think of is to add another value and test if that is yes or no, like so:

If Not _FileReadToArray($LogFile, $aFile) Then

MsgBox(4096, "Error", " Error reading log to Array error:" & @error)

else

$aFileload = True

Exit

EndIf

if $aFileload Then

MsgBox(4096, "$aFileload true?", "Yes")

Else

MsgBox(4096, "$aFileload true?", "No")

EndIf

but this looks....like there is a much smarter way of doing it?

Posted

Melba23,

This gets the job done *facepalm* so unless there is something way smarter, i'ma gonna go with this i guess

if $aFile = "" Then

MsgBox(4096, "$aFileload true?", "Yes")

Else

MsgBox(4096, "$aFileload true?", "No")

EndIf

  • Moderators
Posted

Cartoondragon,

That is a perfectly good check. Another would be to use UBound and see if you get a return. :)

M23

P.S. There is an "Edit" button for each post, by the way. :)

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

 

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
  • Recently Browsing   0 members

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