JohnRichard Posted April 25, 2009 Share Posted April 25, 2009 Just want to ask how will i set this data into listviewitem. this data is generated from a file... 192.168.1.6 | HP-968B0D898 | Administrator|16:44:31|24/04/2009 192.168.1.6 | HP-968B0D898 | Administrator|16:45:08|24/04/2009 192.168.1.6 | HP-968B0D898 | Administrator|16:45:14|24/04/2009 Thanks for any ideas and helpfrom you all. Link to comment Share on other sites More sharing options...
JohnRichard Posted April 25, 2009 Author Share Posted April 25, 2009 Just want to ask how will i set this data into listviewitem. this data is generated from a file... 192.168.1.6 | HP-968B0D898 | Administrator|16:44:31|24/04/2009 192.168.1.6 | HP-968B0D898 | Administrator|16:45:08|24/04/2009 192.168.1.6 | HP-968B0D898 | Administrator|16:45:14|24/04/2009 Thanks for any ideas and helpfrom you all. is there a way to load this data into a Listview? i have tried to load a data in Combobox reading from data in a file. Now i wanted to load this data into a Listview GUI. can somebody help me here? thankyou. Link to comment Share on other sites More sharing options...
Spiff59 Posted April 25, 2009 Share Posted April 25, 2009 I'm not sure what you're asking... Do you mean how to get your input data into a state ready to put into a listview? Or, if you already have it in an array, for instance, then sticking it a listview is practically already layed out on the helpfile, like: #include <GuiListView.au3> Dim $data_array[4] = ["", "192.168.1.6 | HP-968B0D898 | Administrator|16:44:31|24/04/2009", _ "192.168.1.6 | HP-968B0D898 | Administrator|16:45:08|24/04/2009", _ "192.168.1.6 | HP-968B0D898 | Administrator|16:45:14|24/04/2009"] Dim $data_count = 3 $GUI = GuiCreate("", 600, 300, 300, 300) GUISetFont(9, 400, 0, "Lucida Console") $hListView = GuiCtrlCreateListView("", 5, 5, 550, 200) _GUICtrlListView_AddColumn($hListView, "IP ADDRESS", 120) _GUICtrlListView_AddColumn($hListView, "COMPUTER TYPE", 120) _GUICtrlListView_AddColumn($hListView, "USER", 124) _GUICtrlListView_AddColumn($hListView, "DATE", 90) _GUICtrlListView_AddColumn($hListView, "TIME", 90) GUISetState(@SW_SHOW, $GUI) For $x = 1 to $data_count $y = StringSplit($data_array[$x], "|") _GUICtrlListView_AddItem($hListView, $y[1]) _GUICtrlListView_AddSubItem($hListView, $x - 1, $y[2], 1) _GUICtrlListView_AddSubItem($hListView, $x - 1, $y[3], 2) _GUICtrlListView_AddSubItem($hListView, $x - 1, $y[5], 3) _GUICtrlListView_AddSubItem($hListView, $x - 1, $y[4], 4) Next Sleep(5000) Link to comment Share on other sites More sharing options...
JohnRichard Posted April 26, 2009 Author Share Posted April 26, 2009 Do you mean how to get your input data into a state ready to put into a listview? - I think YES. Basically the data that will be put in the Listview will be read from a text file. Just don't know how will i put this data when i load the listview GUI. Have done it with iniwrite and iniread by it loads only the first line of the inifile. Its a TCPSend/Receive where data will come from While 1 $CONNECTED_SOCKET[$CURRENT_SOCKET] = TCPAccept($TCP_SERVER) For $INDEX = 0 To $CONNECTED_SOCKET $RECV = TCPRecv($CONNECTED_SOCKET[$CONNECTED_SOCKET],512) If $RECV <> "" Then $SPLIT2 = StringSplit($RECV, "|",0) If IsArray($SPLIT2) Then If $SPLIT2[0] = 3 Then $time = @HOUR & ":" & @MIN & ":" & @SEC $date = @MDAY & "/" & @MON & "/" & @YEAR $tmp = $SPLIT2[1] & "|" & $SPLIT2[2] & "|" & $SPLIT2[3] & "|" & $time & "|" & $date $log &= $tmp & @CRLF IniWrite(@DesktopDir & "\log.ini", "LOGLIST", "LOG", $log) EndIf EndIf Next Wend Func Listview() $inilog = IniRead(@DesktopDir & "\log.ini", "LOGLIST", "LOG", "") $ListviewGUILast = GUICreate("Connection Log", 547, 150, -1, -1, $WS_SYSMENU) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUILog") $Listview1 = GUICtrlCreateListView("", 10, 10, 520, 100) _GUICtrlListView_AddColumn ($ListView1, "IP Address", 120, 2) _GUICtrlListView_AddColumn ($ListView1, "Computer Name", 100, 2) _GUICtrlListView_AddColumn ($ListView1, "User ID", 100, 2) _GUICtrlListView_AddColumn ($Listview1, "Connect Time", 100, 2) _GUICtrlListView_AddColumn ($Listview1, "Connect Date", 100, 2) GUICtrlSetData($Listview1, $inilog) GUISetState(@SW_SHOW) EndFunc Link to comment Share on other sites More sharing options...
Spiff59 Posted April 26, 2009 Share Posted April 26, 2009 I'm not aware of any method of loading the entire ListView in one fell swoop, or even an entire row at one time. I think using a plain text file might behave better than using the Ini functions. Something like: expandcollapse popup#include <file.au3> Func Build_LogFile() $logfile = FileOpen(@DesktopDir & "log.txt", 2) While 1 $CONNECTED_SOCKET[$CURRENT_SOCKET] = TCPAccept($TCP_SERVER) For $INDEX = 0 To $CONNECTED_SOCKET $RECV = TCPRecv($CONNECTED_SOCKET[$CONNECTED_SOCKET],512) If $RECV Then $SPLIT2 = StringSplit($RECV, "|",0) If Isarray($SPLIT2) Then If $SPLIT2[0] = 3 Then $time = @HOUR & ":" & @MIN & ":" & @SEC $date = @MDAY & "/" & @MON & "/" & @YEAR FileWriteLine($logfile, $SPLIT2[1] & "|" & $SPLIT2[2] & "|" & $SPLIT2[3] & "|" & $time & "|" & $date) EndIf EndIf EndIf Next Wend FileClose($logfile) EndFunc Func Listview() $ListviewGUILast = GUICreate("Connection Log", 547, 150, -1, -1, $WS_SYSMENU) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUILog") $Listview1 = GUICtrlCreateListView("", 10, 10, 520, 100) _GUICtrlListView_AddColumn ($ListView1, "IP Address", 120, 2) _GUICtrlListView_AddColumn ($ListView1, "Computer Name", 100, 2) _GUICtrlListView_AddColumn ($ListView1, "User ID", 100, 2) _GUICtrlListView_AddColumn ($Listview1, "Connect Time", 100, 2) _GUICtrlListView_AddColumn ($Listview1, "Connect Date", 100, 2) _FileReadToArray(@DesktopDir & "log.txt",$aLogfile) For $x = 1 to $aLogfile[0] $y = StringSplit($aLogfile[$x], "|") _GUICtrlListView_AddItem($hListView, $y[1]) _GUICtrlListView_AddSubItem($hListView, $x - 1, $y[2], 1) _GUICtrlListView_AddSubItem($hListView, $x - 1, $y[3], 2) _GUICtrlListView_AddSubItem($hListView, $x - 1, $y[5], 3) _GUICtrlListView_AddSubItem($hListView, $x - 1, $y[4], 4) Next GUISetState(@SW_SHOW) EndFunc Link to comment Share on other sites More sharing options...
JohnRichard Posted April 26, 2009 Author Share Posted April 26, 2009 Hi Spiff. Yeah your right. Txt file would be better rather than ini. have tried this one but could not load any data...something wrong on this? expandcollapse popupWhile 1 $CONNECTED_SOCKET[$CURRENT_SOCKET] = TCPAccept($TCP_SERVER) For $INDEX = 0 To $CONNECTED_SOCKET $RECV = TCPRecv($CONNECTED_SOCKET[$CONNECTED_SOCKET],512) If $RECV Then $SPLIT2 = StringSplit($RECV, "|",0) If Isarray($SPLIT2) Then If $SPLIT2[0] = 3 Then $time = @HOUR & ":" & @MIN & ":" & @SEC $date = @MDAY & "/" & @MON & "/" & @YEAR $tmp = $SPLIT[1] & "|" & $SPLIT[2] & "|" & $SPLIT[3] & "|" & $time & "|" & $date $log &= $tmp & @CRLF FileWriteLine(@DesktopDir & "\log.ini", $log) ;FileWriteLine($logfile, $SPLIT2[1] & "|" & $SPLIT2[2] & "|" & $SPLIT2[3] & "|" & $time & "|" & $date) EndIf EndIf EndIf Next Wend ;FileClose($logfile) Func Listview() Local $i $inilogarray = StringSplit(FileRead(@DesktopDir & "\log.ini"), @CRLF, 1) $ListviewGUILast = GUICreate("Connection Log", 547, 150, -1, -1, $WS_SYSMENU) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUILog") $Listview1 = GUICtrlCreateListView("", 10, 10, 520, 100) _GUICtrlListView_AddColumn ($ListView1, "IP Address", 120, 2) _GUICtrlListView_AddColumn ($ListView1, "Computer Name", 100, 2) _GUICtrlListView_AddColumn ($ListView1, "User ID", 100, 2) _GUICtrlListView_AddColumn ($Listview1, "Connect Time", 100, 2) _GUICtrlListView_AddColumn ($Listview1, "Connect Date", 100, 2) GUISetState(@SW_SHOW) While $i <= $inilogarray[0] $i += 1 GUICtrlSetData($Listview1, $inilogarray) WEnd EndFunc i'm wondering from your post if $logfile should be $aLogfile Link to comment Share on other sites More sharing options...
Spiff59 Posted April 26, 2009 Share Posted April 26, 2009 I used $Logfile as the file handle for FIleOpen(), $FileWriteLine() and FileClose(). The $aLogfile is a separate variable, returned by _FileReadToArray(), I just used the "a" to signify that it is an array. You should be able to display your log.txt file and see that it is correct. You could add an _ArrayDisplay($aLogfile) after the _FileReadToArray() to ensure that it's loaded properly. The examples you've posted must be incomplete? As there are undeclared variables, and there is no actual call to the ListView() function. In those examples ListView() is never executed. Link to comment Share on other sites More sharing options...
JohnRichard Posted April 26, 2009 Author Share Posted April 26, 2009 I used $Logfile as the file handle for FIleOpen(), $FileWriteLine() and FileClose().The $aLogfile is a separate variable, returned by _FileReadToArray(), I just used the "a" to signify that it is an array.You should be able to display your log.txt file and see that it is correct.You could add an _ArrayDisplay($aLogfile) after the _FileReadToArray() to ensure that it's loaded properly.The examples you've posted must be incomplete?As there are undeclared variables, and there is no actual call to the ListView() function. In those examples ListView() is never executed.i see that. thanks... forgive me coz i'm still new to AutoIt and starting to enjoy using it...i just really need how will i set the data that will be written in a text fileyap that script is incomplete. list view will be called using right click context menu,,,,i'll post the complete script... Link to comment Share on other sites More sharing options...
JohnRichard Posted April 26, 2009 Author Share Posted April 26, 2009 Hi Spiff. Here is my complete code. i copied the listview function on your previous post. basically this is a client/server. when client sext uccessfully connects to server, it will send data like IPAdd, PCname, IP and so on...When server receives it, it will be written these data into a text file. When i call on the listview using the Connection Log context menu, it like the data from the text file to be loaded in the LIstview. I have tried using the Filecountlines to count how many records are there in the the text file. i think that will help to how many records will be written on the listview...but im stuck on this part...hope ypu can help me to figure it out or is there other way to do it? here is the code: expandcollapse popup#Include <GuiListView.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <String.au3> #Include <Constants.au3> #include <file.au3> #include <ListviewConstants.au3> #Include <GuiListView.au3> #include <GuiEdit.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> Opt("TrayMenuMode",1) Global $CURRENT_SOCKET Global $CONNECTED_SOCKET[3] Global $TCP_SERVER Global $SPLIT[3], $RECV Global $Form1, $tmp, $time, $date, $listview, $gui_listview, $ListView1, $ListviewGUILast, $aLogfile $accept = TrayCreateItem("Accept Connection") TrayCreateItem("") $show_log = TrayCreateItem("Connection Log") TrayCreateItem("") $close = TrayCreateItem("Close") TraySetState() While 1 $logfile = FileOpen(@DesktopDir & "\log.txt", 1) $msg = TrayGetMsg() Select Case $msg = $accept ReConnect() Case $msg = $show_log Listview() Case $msg = $close CloseServer() EndSelect $CONNECTED_SOCKET[$CURRENT_SOCKET] = TCPAccept($TCP_SERVER) If $CONNECTED_SOCKET[$CURRENT_SOCKET] <> -1 Then $CURRENT_SOCKET += 1 Switch $CURRENT_SOCKET Case $CURRENT_SOCKET = 1 For $INDEX = 0 To $CONNECTED_SOCKET $RECV = TCPRecv($CONNECTED_SOCKET[$CONNECTED_SOCKET],512) If $RECV <> "" Then $SPLIT2 = StringSplit($RECV, "|",0) If IsArray($SPLIT2) Then If $SPLIT2[0] = 3 Then $time = @HOUR & ":" & @MIN & ":" & @SEC $date = @MDAY & "/" & @MON & "/" & @YEAR $tmp = $SPLIT2[1] & "|" & $SPLIT2[2] & "|" & $SPLIT2[3] & "|" & $time & "|" & $date FileWriteLine($logfile, $SPLIT2[1] & "|" & $SPLIT2[2] & "|" & $SPLIT2[3] & "|" & $time & "|" & $date) EndIf EndIf EndIf Next EndSwitch EndIf Wend FileClose($logfile) Func ReConnect() TCPShutdown() $TCP = TCPStartup() $TCP_SERVER = TCPListen(@IPAddress1,7000,16) $CURRENT_SOCKET = 0 ENdFunc Func Listview() Dim $aLogfile $ListviewGUILast = GUICreate("Connection Log", 547, 150, -1, -1, $WS_SYSMENU) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseServer") $Listview1 = GUICtrlCreateListView("", 10, 10, 520, 100) _GUICtrlListView_AddColumn ($ListView1, "IP Address", 120, 2) _GUICtrlListView_AddColumn ($ListView1, "Computer Name", 100, 2) _GUICtrlListView_AddColumn ($ListView1, "User ID", 100, 2) _GUICtrlListView_AddColumn ($Listview1, "Connect Time", 100, 2) _GUICtrlListView_AddColumn ($Listview1, "Connect Date", 100, 2) _FileReadToArray(@DesktopDir & "log.txt",$aLogfile) For $x = 1 to $aLogfile[0] $y = StringSplit($aLogfile[$x], "|") _GUICtrlListView_AddItem($ListView, $y[1]) _GUICtrlListView_AddSubItem($ListView1, $x - 1, $y[2], 1) _GUICtrlListView_AddSubItem($ListView1, $x - 1, $y[3], 2) _GUICtrlListView_AddSubItem($ListView1, $x - 1, $y[5], 3) _GUICtrlListView_AddSubItem($ListView1, $x - 1, $y[4], 4) Next GUISetState(@SW_SHOW) EndFunc Func CloseServer() Exit EndFunc Link to comment Share on other sites More sharing options...
Spiff59 Posted April 27, 2009 Share Posted April 27, 2009 You left a "1" off the ListView handle in this line: _GUICtrlListView_AddItem($ListView, $y[1]) Other than that, if there is something in the log.txt file, then the listview() fnction works. Link to comment Share on other sites More sharing options...
JohnRichard Posted April 27, 2009 Author Share Posted April 27, 2009 You left a "1" off the ListView handle in this line: _GUICtrlListView_AddItem($ListView, $y[1]) Other than that, if there is something in the log.txt file, then the listview() fnction works. hi Spiff. how are you today. still stuck on this one. i missed to put 1 in this line... _GUICtrlListView_AddItem($ListView, $y[1]) i changed it now to... _GUICtrlListView_AddItem($ListView1, $y[1]) but when i tried to execute and call the Listview, i have this error... Subscript used with non-Array variable.: For $x = 1 to $aLogfile[0] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now