Sign in to follow this  
Followers 0
CartoonDragon

text to array to be displayed in gui problem

3 posts in this topic

Hello guys,

I've run in to a problem and i must admit i don't know how to begin to tackle it. I have a big text file that i want to run in to an array (so far i can do that) and then show the output in a "List View". The content of the text file looks like this:

"2011-03-15 16:56:48, John Doh (jd), \\fs6\privat$\Ansatte\jd (\\fs6\privat$\Ansatte\jsm), k11607, 10.1.1.112 - fe80::1dd7:638b:d380:be9a"

and i want to seperate at each "," and put them in a nice output with coloms in a gui like the example script called "_GUICtrlListView_AddArray.au3"

basicly it falls down to me not understanding how to split it in to an array and then displaying the array, any help is warmly welcome as i have been unable to find anything that can help me understand what i need to do so far.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

here's a rough example you can try

#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

If your having problems getting the expected results then post an example text file for me to work with.

The text file I tested with was just the one example line you gave repeated 5000 times saved as LargeTextfile.txt

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

Thank you so much smashly that works perfectly

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  
Followers 0