Sign in to follow this  
Followers 0
seesoe

do until in listview

20 posts in this topic

hello, i have a list view with a|b|c headers at the top

i have a text file that i am trying to read and put into the list.

the file has a bunch of lines like this (these lines are for examples sake)

[a=1~b=3~c=5]

[a=2~b=4~c=6]

i know how to break the data up and manually set the items in the list, but i want to read the file automatically and put all the lines in the list

Share this post


Link to post
Share on other sites



Start out by trimming the '[]' off the ends with StringTrimLeft() and StringTrimRight(). Then use StringSplit() using the delimeter '~'. This should split up the lines into a=1 b=3 c=5 etc... Try to go from there.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

i have that part already done, but that for a single string

how do i read each line in the file and do that to each line of string and put it in the list?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If each set is on a single line alone, you could use StringSplit() with a delimeter of @Crlf or something like that. You could also choose to remove the carriage returns and then split the string based upon '[]'. Hope this helps.Then put each line into an array. Do something with the array like this:

For $element In $Array

; manipulate the element

Next

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

i have that part already done, but that for a single string

how do i read each line in the file and do that to each line of string and put it in the list?

something like:

$array = inireadsection("myfile.ini","section")

For $i = 1 to $array[0][0]
guictrlcreatelistviewitem($array[$i][1],$listview)
Next

[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

You could also read the number of lines in the file and then do:

$Handle = FileOpen($File, 1)

For $x = 1 to $NumberofLines

$Line[$x] = FileReadLine($Handle, $x)

Next


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

hmmm.... i got confused real quick on this one lol

lets just put each set of [] in the first list column just for now,

$Handle = FileOpen($done,1)
$done_breaks = StringSplit(FileRead($Handle),@Crlf)

For $i = 1 to $done_breaks[0][0]
guictrlcreatelistviewitem($done_breaks[$i][1],$history)
Next

....?

Edited by seesoe

Share this post


Link to post
Share on other sites

hmmm.... i got confused real quick on this one lol

lets just put each set of [] in the first list column just for now,

$Handle = FileOpen($done,1)
$done_breaks = StringSplit(FileRead($Handle),@Crlf)

For $i = 1 to $done_breaks[0][0]
guictrlcreatelistviewitem($done_breaks[$i][1],$history)
Next

....?

stringsplit only returns a one dimensional array, so you would just use $done_breaks[0] and then $done_breaks[$i] in the For Next loop

[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

that still doesn't work.., i didn't think this task would be so complex, ive always hated arrays

Share this post


Link to post
Share on other sites

#include <Array.au3>

Dim $sText = '[a=1~b=3~c=5]' & @CRLF & '[a=2~b=4~c=6]' & @CRLF & _
             '[a=1~b=3~c=5]' & @CRLF & '[a=2~b=4~c=6]' & @CRLF & _
             '[a=1~b=3~c=5]' & @CRLF & '[a=2~b=4~c=6]' & @CRLF & _
             '[a=1~b=3~c=5]' & @CRLF & '[a=2~b=4~c=6]'
Dim $aLines = StringSplit($sText, @CRLF, 1)
Dim $iCounter = 1

Dim $hGUI = GUICreate('Test', 300, 500)
Dim $ListView = GUICtrlCreateListView('a           |b           |c           ', 0, 0, 240, 390)
            

For $sLine In $aLines
    Local $aMatches = StringRegExp($sLine, '=(\d+)', 3)
    Local $sItem = ''
    If IsArray($aMatches) Then
        For $i = 0 To UBound($aMatches)-1
            $sItem &= $aMatches[$i] & '|'
        Next
        GUICtrlCreateListViewItem(StringTrimRight($sItem, 1), $ListView)
    EndIf
Next

GUISetState()

Do
    Sleep(20)
Until GUIGetMsg() = -3oÝ÷ Øò¢éÞyÛaz+^̨¹Æ§©jv«­¬Û-¢·¢¶X¤zØb±«­¢+Ù¥´ÀÌØí%ѵÍlÅt()½ÈÀÌØíÍ1¥¹%¸ÀÌØí1¥¹Ì(%1½°ÀÌØí5Ñ¡ÌôMÑÉ¥¹IáÀ ÀÌØíÍ1¥¹°Ìäìô ÀäÈí¬¤Ìäì°Ì¤(%1½°ÀÌØíÍ%Ñ´ôÌäìÌäì(%%%ÍÉÉä ÀÌØí5ѡ̤Q¡¸($%½ÈÀÌØí¤ôÀQ¼U   ½Õ¹ ÀÌØí5ѡ̤´Ä($$$ÀÌØíÍ%Ñ´µÀìôÀÌØí5Ñ¡ÍlÀÌØí¥tµÀìÌäíðÌäì($%9áÐ(I¥´ÀÌØí%ѵÍmU   ½Õ¹ ÀÌØí%ѵ̤¬Åt($$ÀÌØí%ѵÍmU   ½Õ¹ ÀÌØí%ѵ̤´ÅtôU%
Ñɱ
ÉÑ1¥ÍÑY¥Ý%Ñ´¡MÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØíÍ%Ñ´°Ä¤°ÀÌØí1¥ÍÑY¥Ü¤(%¹%)9áÐ((ÀÌØí%ѵÍlÁtôU ½Õ¹ ÀÌØí%ѵ̤´Ä

or you can use counter as it's much simpler and clearer and faster ;]

Share this post


Link to post
Share on other sites

This follows the train of thought you were working on, but you still have to strip the brackets, or not use them at all:

#include <GuiConstants.au3>
#include <File.au3>

$done = "test.txt"

$Handle = FileOpen($done,0)
$done_breaks = _FileCountLines($done)

$main = GuiCreate("listview from file",200,200)

$history = GuiCtrlCreateListView("field 1|field 2|field 3",5,5,190,190)

For $i = 1 to $done_breaks
$split = StringSplit(FileReadLine($Handle, $i),"~")
guictrlcreatelistviewitem($split[1] & "|" & $split[2] & "|" & $split[3],$history)
Next

FileClose($Handle)

GUISetState()
Do
    $msg = GUIGetMsg()
    
    Until $msg = $GUI_EVENT_CLOSE
GUIDelete($main)

[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

aha! sweet, i started working with Authenticity's code for a bit and it worked pretty nice, but 30min later it was giving me trouble translating it to my project.

i came back to post for help, and i see maqleod's script and yes that is correct it is much more around the lines of what i need, i can easily modify it to my setup. im working with it now, ill post back my final results.

thank you all so much!

cheers

seesoe :D

Edited by seesoe

Share this post


Link to post
Share on other sites

here pretty much what i got going, works just like i wanted:), thank you all very much!

Func read_done()
    $Handle = FileOpen($done,0)
    $done_breaks = _FileCountLines($done)
    For $i = 1 to $done_breaks
        $file_line_1    =   StringTrimLeft(FileReadLine($Handle, $i), 1)
        $file_line_2    =   StringTrimRight($file_line_1, 1)
        $file_line_3    =   StringSplit($file_line_2, "~")

        $id             =   StringTrimLeft($file_line_3[1], 3)
        $at             =   StringTrimLeft($file_line_3[2], 3)

        $from_1         =   StringTrimLeft($file_line_3[3], 5)
        $from           =   StringSplit($from_1,",")

        $has            =   StringTrimLeft($file_line_3[4], 4)
        $list_1 = StringSplit($has,",")

        $for            =   StringTrimLeft($file_line_3[5], 4)
        $total          =   StringSplit($for,",")
        guictrlcreatelistviewitem($id & "|" & $at & "|" & $from[1] & "|" & $from[2] & "|" & $from[3] & "|" & $list_1[0] & "|" & $total[3],$history)
    Next
    FileClose($Handle)
EndFunc

one thing im trying to do with it is keep monitoring the file so that i can have a live update list view, or at least every time its update refresh or something, i tried doing some things, but the data in the list would list exponentially.

Share this post


Link to post
Share on other sites

you can try using _GUICtrlListView_DeleteAllItems($history) (requires #include <GuiListView.au3>) to clear the listview so that when you run the function again it will only contain that instance of the file.


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

i was thinking the exact same thing, clear it then call the function again, now it really all works 100%, more then satisfaction:D.

i have a website where people place orders online, then the data gets sent to this script (socket server) and the order prints on a thermal printer, what we did in this thread is to keep records and live update of orders coming in.

thanks once again

cheers

seeose.

Share this post


Link to post
Share on other sites

is there a way to detect what item in the list is selected and put the data somewhere?

Share this post


Link to post
Share on other sites

is there a way to detect what item in the list is selected and put the data somewhere?

yes, it would be something like this:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <File.au3>

$done = "test.txt"

$Handle = FileOpen($done,0)
$done_breaks = _FileCountLines($done)

$main = GuiCreate("listview from file",200,250)

$history = GuiCtrlCreateListView("field 1|field 2|field 3",5,5,190,190)
$button = GuiCtrlCreateButton("Report",65,215,75,25)

For $i = 1 to $done_breaks
$split = StringSplit(FileReadLine($Handle, $i),"~")
guictrlcreatelistviewitem($split[1] & "|" & $split[2] & "|" & $split[3],$history)
Next

FileClose($Handle)

GUISetState()
Do
    $msg = GUIGetMsg()
    
    if $msg = $button Then
        $index = _GUICtrlListView_GetSelectionMark($history)
        if $index = -1 Then
            MsgBox(64,"Error","Please make a selection in the listview")
        else
            $field1 = _GUICtrlListView_GetItemText($history, $index,0)
            $field2 = _GUICtrlListView_GetItemText($history, $index,1)
            $field3 = _GUICtrlListView_GetItemText($history, $index,2)
            MsgBox(64,"Report",$field1 & @CRLF & $field2 & @CRLF & $field3)
        endif
    endif
    
    Until $msg = $GUI_EVENT_CLOSE
GUIDelete($main)

[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

works like a charm, is there a way to make it where if i double click on the item it will open it?

Share this post


Link to post
Share on other sites

hmmm, i noticed with vista x64 (even x32) that the $WM_NOTIFY doesn't work, like in that code, its ok i will settle with clicking the button:)

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