Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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?

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
Posted

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

Posted

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
Posted

#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 ;]

Posted

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
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
Posted

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.

Posted

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
Posted

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.

Posted

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
Posted

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:)

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
×
×
  • Create New...