Jump to content

do until in listview


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
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
Link to comment
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
Link to comment
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 ;]

Link to comment
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
Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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.

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

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