searchresult Posted May 7, 2007 Share Posted May 7, 2007 (edited) I have tried to get it work but just wont happen. Every time I tried something, I would never get an error, script works fine but the txt file is always empty. expandcollapse popup#include <GUIConstants.au3> #include <file.au3> #include <GuiList.au3> #include <date.au3> #Include <GuiListView.au3> $Form1 = GUICreate("Form1", 506, 240, 193, 115) GUISetIcon("logo.ico") $Button1 = GUICtrlCreateButton("Add", 8, 120, 99, 25, 0) $Button2 = GUICtrlCreateButton("Remove", 8, 152, 99, 25, 0) $Pic1 = GUICtrlCreatePic("logo.jpg", 8, 8, 100, 100, BitOR($SS_NOTIFY,$WS_GROUP)) $Button3 = GUICtrlCreateButton("Save", 8, 184, 99, 26, 0) $List1 = GUICtrlCreateList("", 112, 8, 385, 201) $MenuItem1 = GUICtrlCreateMenu("&File") $MenuItem2 = GUICtrlCreateMenuItem("Add", $MenuItem1) $MenuItem3 = GUICtrlCreateMenuItem("Remove", $MenuItem1) $MenuItem5 = GUICtrlCreateMenuItem("Save", $MenuItem1) $MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MenuItem4 Exit Case $MenuItem2 $message = "Hold down Ctrl or Shift to choose multiple files." $var = FileOpenDialog($message, @ProgramFilesDir & "\", "Executable files (*.exe)", 1 + 4 ) _GUICtrlListAddItem($List1,$var) Case $Button1 $message = "Hold down Ctrl or Shift to choose multiple files." $var = FileOpenDialog($message, @ProgramFilesDir & "\", "Executable files (*.exe)", 1 + 4 ) _GUICtrlListAddItem($List1,$var) Case $MenuItem3 $line = _GUICtrlListSelectedIndex ($List1) _GUICtrlListDeleteItem ( $List1, $line ) Case $Button2 $line = _GUICtrlListSelectedIndex ($List1) _GUICtrlListDeleteItem ( $List1, $line ) Case $MenuItem5 ;- need code to put items from a list to a text file Case $Button3 ;- need code to put items from a list to a text file EndSwitch WEnd Here is a code with need code part cause I don't know what to do. Any ideas??? Edited May 7, 2007 by searchresult Link to comment Share on other sites More sharing options...
evilertoaster Posted May 7, 2007 Share Posted May 7, 2007 _GUICtrlListGetText () and FileWrite() should be the only 2 function you need to create such a feature. Do you have an attempt at doing this you'd like to post? Link to comment Share on other sites More sharing options...
searchresult Posted May 7, 2007 Author Share Posted May 7, 2007 _GUICtrlListGetText () and FileWrite() should be the only 2 function you need to create such a feature. Do you have an attempt at doing this you'd like to post? expandcollapse popup#include <GUIConstants.au3> #include <file.au3> #include <GuiList.au3> #include <date.au3> #Include <GuiListView.au3> $Form1 = GUICreate("Form1", 506, 240, 193, 115) GUISetIcon("logo.ico") $Button1 = GUICtrlCreateButton("Add", 8, 120, 99, 25, 0) $Button2 = GUICtrlCreateButton("Remove", 8, 152, 99, 25, 0) $Pic1 = GUICtrlCreatePic("logo.jpg", 8, 8, 100, 100, BitOR($SS_NOTIFY,$WS_GROUP)) $Button3 = GUICtrlCreateButton("Save", 8, 184, 99, 26, 0) $List1 = GUICtrlCreateList("", 112, 8, 385, 201) $MenuItem1 = GUICtrlCreateMenu("&File") $MenuItem2 = GUICtrlCreateMenuItem("Add", $MenuItem1) $MenuItem3 = GUICtrlCreateMenuItem("Remove", $MenuItem1) $MenuItem5 = GUICtrlCreateMenuItem("Save", $MenuItem1) $MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MenuItem4 Exit Case $MenuItem2 $message = "Hold down Ctrl or Shift to choose multiple files." $var = FileOpenDialog($message, @ProgramFilesDir & "\", "Executable files (*.exe)", 1 + 4 ) _GUICtrlListAddItem($List1,$var) Case $Button1 $message = "Hold down Ctrl or Shift to choose multiple files." $var = FileOpenDialog($message, @ProgramFilesDir & "\", "Executable files (*.exe)", 1 + 4 ) _GUICtrlListAddItem($List1,$var) Case $MenuItem3 $line = _GUICtrlListSelectedIndex ($List1) _GUICtrlListDeleteItem ( $List1, $line ) Case $Button2 $line = _GUICtrlListSelectedIndex ($List1) _GUICtrlListDeleteItem ( $List1, $line ) Case $MenuItem5 SaveListView($List1, 'C:\listview_data.txt') Case $Button3 ;- need code to put items from a list to a text file EndSwitch WEnd Func SaveListView($list, $file) $data = '' For $i = 0 To _GUICtrlListViewGetItemCount($list) - 1 $data &= _GUICtrlListViewGetItemText($list, $i) & @CRLF Next $data = StringTrimRight($data,2) FileDelete($file) FileWrite($file, $data) EndFunc I have tried with this also no error works fine but the file is empty. Link to comment Share on other sites More sharing options...
evilertoaster Posted May 7, 2007 Share Posted May 7, 2007 expandcollapse popup#include <GUIConstants.au3> #include <file.au3> #include <GuiList.au3> #include <date.au3> #Include <GuiListView.au3> $Form1 = GUICreate("Form1", 506, 240, 193, 115) GUISetIcon("logo.ico") $Button1 = GUICtrlCreateButton("Add", 8, 120, 99, 25, 0) $Button2 = GUICtrlCreateButton("Remove", 8, 152, 99, 25, 0) $Pic1 = GUICtrlCreatePic("logo.jpg", 8, 8, 100, 100, BitOR($SS_NOTIFY,$WS_GROUP)) $Button3 = GUICtrlCreateButton("Save", 8, 184, 99, 26, 0) $List1 = GUICtrlCreateList("", 112, 8, 385, 201) $MenuItem1 = GUICtrlCreateMenu("&File") $MenuItem2 = GUICtrlCreateMenuItem("Add", $MenuItem1) $MenuItem3 = GUICtrlCreateMenuItem("Remove", $MenuItem1) $MenuItem5 = GUICtrlCreateMenuItem("Save", $MenuItem1) $MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MenuItem4 Exit Case $MenuItem2 $message = "Hold down Ctrl or Shift to choose multiple files." $var = FileOpenDialog($message, @ProgramFilesDir & "\", "Executable files (*.exe)", 1 + 4 ) _GUICtrlListAddItem($List1,$var) Case $Button1 $message = "Hold down Ctrl or Shift to choose multiple files." $var = FileOpenDialog($message, @ProgramFilesDir & "\", "Executable files (*.exe)", 1 + 4 ) _GUICtrlListAddItem($List1,$var) Case $MenuItem3 $line = _GUICtrlListSelectedIndex ($List1) _GUICtrlListDeleteItem ( $List1, $line ) Case $Button2 $line = _GUICtrlListSelectedIndex ($List1) _GUICtrlListDeleteItem ( $List1, $line ) Case $MenuItem5 SaveListView($List1, 'C:\listview_data.txt') Case $Button3 ;- need code to put items from a list to a text file EndSwitch WEnd Func SaveListView($list, $file) $data = '' For $i = 0 To _GUICtrlListGetInfo($list) - 1 $data &= _GUICtrlListGetText($list, $i) & @CRLF Next $data = StringTrimRight($data,2) FileDelete($file) FileWrite($file, $data) EndFunc Its a list not a listview Link to comment Share on other sites More sharing options...
searchresult Posted May 7, 2007 Author Share Posted May 7, 2007 Its a list not a listviewSo what should be the solution? Link to comment Share on other sites More sharing options...
xcal Posted May 7, 2007 Share Posted May 7, 2007 (edited) Here's my (working) version. I also fixed the problem with selecting multiple files. expandcollapse popup#include <GUIConstants.au3> #include <file.au3> #include <GuiList.au3> #include <date.au3> #Include <GuiListView.au3> $Form1 = GUICreate("Form1", 506, 240, 193, 115) GUISetIcon("logo.ico") $Button1 = GUICtrlCreateButton("Add", 8, 120, 99, 25, 0) $Button2 = GUICtrlCreateButton("Remove", 8, 152, 99, 25, 0) $Pic1 = GUICtrlCreatePic("logo.jpg", 8, 8, 100, 100, BitOR($SS_NOTIFY, $WS_GROUP)) $Button3 = GUICtrlCreateButton("Save", 8, 184, 99, 26, 0) $List1 = GUICtrlCreateList("", 112, 8, 385, 201) $MenuItem1 = GUICtrlCreateMenu("&File") $MenuItem2 = GUICtrlCreateMenuItem("Add", $MenuItem1) $MenuItem3 = GUICtrlCreateMenuItem("Remove", $MenuItem1) $MenuItem5 = GUICtrlCreateMenuItem("Save", $MenuItem1) $MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MenuItem4 Exit Case $MenuItem2 addtolist() Case $Button1 addtolist() Case $MenuItem3 $line = _GUICtrlListSelectedIndex($List1) _GUICtrlListDeleteItem($List1, $line) Case $Button2 $line = _GUICtrlListSelectedIndex($List1) _GUICtrlListDeleteItem($List1, $line) Case $MenuItem5 savetofile() Case $Button3 savetofile() EndSwitch WEnd Func savetofile() Local $data = '' $fn = FileSaveDialog('Saving to file...', @MyDocumentsDir, 'Text files (*.txt)', 18, 'filename.txt') $file = FileOpen($fn, 2) For $i = 0 To _GUICtrlListGetInfo($List1) $txt = _GUICtrlListGetText($List1, $i) If $txt = -1 Then ContinueLoop If $data = '' Then $data &= $txt Else $data &= @LF & $txt EndIf Next FileWrite($file, $data) FileClose($file) EndFunc Func addtolist() $message = "Hold down Ctrl or Shift to choose multiple files." $var = FileOpenDialog($message, @ProgramFilesDir & "\", "Executable files (*.exe)", 1 + 4) If StringInStr($var, '|') Then $fod = StringSplit($var, '|') For $i = 2 To UBound($fod) - 1 _GUICtrlListAddItem($List1, $fod[1] & '\' & $fod[$i]) Next Else _GUICtrlListAddItem($List1, $var) EndIf EndFunc edit - woops, stray underscore. Edited May 7, 2007 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
evilertoaster Posted May 7, 2007 Share Posted May 7, 2007 my post had a workign version. i simply changed the GUICtrlListViewGetItemCount() and _GUICtrlListViewGetItemText() to their list equivalents. Link to comment Share on other sites More sharing options...
searchresult Posted May 7, 2007 Author Share Posted May 7, 2007 Here's my (working) version. I also fixed the problem with selecting multiple files.edit - woops, stray underscore.Thanks it is working fine but it must be saved without save dialog in a folder where the script is located... Link to comment Share on other sites More sharing options...
xcal Posted May 8, 2007 Share Posted May 8, 2007 Thanks it is working fine but it must be saved without save dialog in a folder where the script is located...So simply change $fn to hold the path to your file. Maybe adjust FileOpen's option, depending on what you want, too. How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
searchresult Posted May 8, 2007 Author Share Posted May 8, 2007 So simply change $fn to hold the path to your file. Maybe adjust FileOpen's option, depending on what you want, too.Thanks I will try Link to comment Share on other sites More sharing options...
searchresult Posted May 12, 2007 Author Share Posted May 12, 2007 That is working fine but when I open file everything is in the same line. I need it to be saved as in the list Link to comment Share on other sites More sharing options...
xcal Posted May 12, 2007 Share Posted May 12, 2007 Look at my savetofile() function. Did you leave out the @LF? How To Ask Questions The Smart Way 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