JohnBailey Posted June 27, 2007 Share Posted June 27, 2007 (edited) This has been answered and is more of an example script now (MODs you can move it to there) expandcollapse popup;=============================================================================== ; Description: Save ListView Content to a file ; ; Parameter(s): $listViewObjectName - var, the variable name for the ListView Object ; $saveToFile - string, Where to save the file and it's name with extention (eg. C:\myListViewContent.txt) ; $hArray - string or array var, Use to save only certain columns to the output file from the listview (eg. '1,2,3') (default = '') (Note: only use , or | as delimiters) ; $cCheck - boolean, Check for (default = false) ; $nCheck - number, Column to check for , which means checked thus save (default = "") ; ; Return Value(s): On Success - 1 = Saved the file ; On Failure - 0 and Sets @Error ; @ERROR - 0 = File could not be created ; - 1 = Probelm with counting the ListView Items ; - 2 = could not write to file ; - 3 = $hArray delimiter used is not , or | or Single number has a space ; ; Note(s): none ;=============================================================================== #include"Array.au3" Func saveListView($listViewObjectName,$saveToFile,$hArray='',$cCheck=false,$nCheck="") If $hArray = -1 Then $hArray='' Local $hhArray _FileCreate($saveToFile) If @error Then SetError(0,@error) Return 0 EndIf Local $list_count = _GUICtrlListViewGetItemCount($listViewObjectName) If @error Then SetError(1) Return 0 EndIf Local $saveArray[1] = [$list_count] If $cCheck Then For $i = 1 To $list_count $sSeltxt = StringSplit(_GUICtrlListViewGetItemText($listViewObjectName, $i - 1), '|') $bCheck = $sSeltxt[$nCheck] Switch $bCheck Case "", " " ;nothing Case Else If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1)) Else If IsArray($hArray) Then Local $hhArray = $hArray Else If StringInStr($hArray,',') > 0 Then ;Remove any spaces in the column choices $hhArray = _ArrayCreate('') Local $ColumnChoiceTogetherAgain = '' Local $hSplitArray = StringSplit($hArray,',',1) for $nnl = 1 to UBound($hSplitArray)-1 _ArrayAdd($hhArray ,StringStripWS($hSplitArray[$nnl],8)) next ElseIf StringInStr($hArray,'|') > 0 Then $hhArray = _ArrayCreate('') Local $ColumnChoiceTogetherAgain = '' Local $hSplitArray = StringSplit($hArray,'|',1) for $nnl = 1 to UBound($hSplitArray)-1 _ArrayAdd($hhArray ,StringStripWS($hSplitArray[$nnl],8)) next Else If StringInStr($hArray,' ') > 0 Then SetError(3) Return 0 Else Local $hhArray = Number($hArray) EndIf EndIf EndIf Local $nArray = _ArrayCreate('') for $nl = 1 to Ubound($hhArray)-1 _ArrayAdd($nArray,_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,$hhArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf EndSwitch Next Else For $i = 1 To $list_count If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1)) Else If IsArray($hArray) Then $hhArray = $hArray Else If StringInStr($hArray,',') > 0 Then ;Remove any spaces in the column choices $hhArray = _ArrayCreate('') Local $ColumnChoiceTogetherAgain = '' Local $hSplitArray = StringSplit($hArray,',',1) for $nnl = 1 to UBound($hSplitArray)-1 _ArrayAdd($hhArray ,StringStripWS($hSplitArray[$nnl],8)) next ElseIf StringInStr($hArray,'|') > 0 Then $hhArray = _ArrayCreate('') Local $ColumnChoiceTogetherAgain = '' Local $hSplitArray = StringSplit($hArray,'|',1) for $nnl = 1 to UBound($hSplitArray)-1 _ArrayAdd($hhArray ,StringStripWS($hSplitArray[$nnl],8)) next Else If StringInStr($hArray,' ') > 0 Then SetError(3) Return 0 Else Local $hhArray = Number($hArray) EndIf EndIf EndIf Local $nArray = _ArrayCreate('') for $nl = 0 to Ubound($hhArray)-1 _ArrayAdd($nArray,_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,$hhArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf Next EndIf $write = _FileWriteFromArray($saveToFile, $saveArray, 1) If @error Then SetError(2) Return 0 EndIf Return 1 EndFuncoÝ÷ ØLZ^jëh×6[code]#include<Array.au3> #include <Constants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> #include <File.au3> #include <Misc.au3> Opt ("GUIOnEventMode", 1) $dll = DllOpen("user32.dll") Global Const $WM_NOTIFY = 0x004E ;Thanks GaFrost Global Const $NM_FIRST = 0 ;Thanks GaFrost Global Const $NM_CLICK = ($NM_FIRST - 2) ;Thanks GaFrost Global Const $NM_DBLCLK = ($NM_FIRST - 3) ;Thanks GaFrost #region Parent GUI Setup $ParentWin = GUICreate('Save List Example', 850, 700,-1,-1,$WS_SIZEBOX+$WS_SYSMENU+$WS_MINIMIZEBOX) $SavingNotice = GUICtrlCreateLabel("Saving...", 280, 100, 150, 17) $ListView1 = GUICtrlCreateListView('Name|Phone Number|Location|Use in Special File', 20, 20, 810, 220, $LVS_SHOWSELALWAYS) _GUICtrlListViewSetColumnWidth($ListView1, 0, 260) $tab = GUICtrlCreateTab(20, 250, 810, 180) GUICtrlSetResizing ($tab,$GUI_DOCKAUTO) GUICtrlCreateTabItem("Edit") $SaveEditsBtn = GUICtrlCreateButton('Save Changes', 370, 290, 80, 24) GUICtrlSetResizing (-1,$GUI_DOCKSIZE) GUICtrlCreateLabel("Account Name:", 30, 295) $editAccountName = GUICtrlCreateInput("", 130, 292, 200, 20) GUICtrlCreateLabel("Account Number:", 30, 325) $editAccountNumber = GUICtrlCreateInput("", 130, 322, 200, 20) GUICtrlCreateLabel("Default Folder:", 30, 355) $editAccountLocation = GUICtrlCreateInput("", 130, 352, 200, 20) $editDate = GUICtrlCreateDate("", 130, 390, 200, 20) $UseinSpecialFileCH = GUICtrlCreateCheckbox("Use in Special File", 375, 330, 120, 17) GUICtrlCreateTabItem("") GUICtrlSetResizing (-1,$GUI_DOCKSIZE) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") ;Thanks GaFrost GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUICtrlSetOnEvent($UseinSpecialFileCH, "ButtonPress") GUICtrlSetOnEvent($SaveEditsBtn, "ButtonPress") GUISetState() #endregion Parent GUI Setup list(@ScriptDir&'\test6-DB.txt',$ListView1) While 1 Sleep(10) If _IsPressed("1B", $dll) Then If WinActive($ParentWin) = 1 Then Terminate() EndIf EndIf WEnd Func list($db, $list) Local $array If Not _FileReadToArray($db, $array) Then MsgBox(4096, "Error", "Edit "&$db &" Error reading log to Array error:" & @error) EndIf For $i = 1 To $array[0] GUICtrlCreateListViewItem($array[$i], $list) Next EndFunc ;==>list #region Button Presses Func ButtonPress() Switch @GUI_CTRLID Case $UseinSpecialFileCH $selected = _GUICtrlListViewGetCurSel($ListView1) If BitAND(GUICtrlRead(@GUI_CTRLID), $GUI_CHECKED) = $GUI_CHECKED Then _GUICtrlListViewSetItemText($ListView1, $selected, 3, "") Else _GUICtrlListViewSetItemText($ListView1, $selected, 3, " ") EndIf Case $SaveEditsBtn Local $selectedAmount = _GUICtrlListViewGetSelectedCount($ListView1) If $selectedAmount > 1 Then MsgBox(0, "Multiple Items Selected", "You have selected: " & $selectedAmount & " items. Only one Item may be selected to make this change.") Else $selected = _GUICtrlListViewGetCurSel($ListView1) _GUICtrlListViewSetItemText($ListView1, $selected, 0, GUICtrlRead($editAccountName)) SavePressed() EndIf EndSwitch EndFunc #endregion Button Presses ; ;Saving function Func SavePressed() GUISetState(@SW_DISABLE, $ParentWin) GUICtrlSetState($SavingNotice,$GUI_SHOW) GUICtrlSetState($ListView1,$GUI_HIDE) saveListView($ListView1,@ScriptDir&'\test6-DB.txt') saveListView($ListView1,@ScriptDir&"\test6-DB-SpecialFile.txt",'0,1,2',true,4) GUICtrlSetState($SavingNotice,$GUI_HIDE) GUICtrlSetState($ListView1,$GUI_SHOW) GUISetState(@SW_ENABLE, $ParentWin) EndFunc Func SpecialEvents() Select Case @GUI_CTRLID = $GUI_EVENT_CLOSE Terminate() Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE ;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) WinSetState($ParentWin, "", @SW_HIDE) TrayTip(@ScriptName, "has been minimzed. Doubleclick here to restore", 10, 0) Case @GUI_CTRLID = $GUI_EVENT_RESTORE MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) EndSelect EndFunc ;thanks GaFrost!! Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView1 Select Case $event = $NM_CLICK ;ConsoleWrite(_GUICtrlListViewGetItemText($ListView1)&@CRLF) $seltxt = StringSplit(_GUICtrlListViewGetItemText($ListView1), '|') If UBound($seltxt) - 1 = 4 Then GUICtrlSetData($editAccountName, $seltxt[1]) GUICtrlSetData($editAccountNumber, $seltxt[2]) GUICtrlSetData($editAccountLocation, $seltxt[3]) Switch $seltxt[4] Case " ","" GUICtrlSetState($UseinSpecialFileCH,$GUI_Unchecked) Case Else GUICtrlSetState($UseinSpecialFileCH,$GUI_Checked) EndSwitch EndIf EndSelect EndSelect $tagNMHDR = 0 $event = 0 $lParam = 0 Return $GUI_RUNDEFMSG EndFunc ;==>WM_Notify_Events Func Terminate() DllClose($dll) Exit EndFuncoÝ÷ Ø6h¬xX¥zÜmr^&¦(¢·µç®;÷^zQ ¹ã«uíùë¿=Û^ ZÓÚºQk¹íu箵ç®|è&§iÖzàxÇ+{]ºãÏ|÷÷(uæÎD4ÐPD ãlÞyÛhi×Z¥ªÚë^©e£§Ø^±Êâ¦×«¶)yÈËbr(駲Ú,j÷®ââ²Õb{®¶sc³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ²FW67&Föã¢6fRÆ7EfWr6öçFVçBFòfÆP£°£²&ÖWFW"2¢b33c¶Æ7EfWtö&¦V7DæÖRÒf"ÂFRf&&ÆRæÖRf÷"FRÆ7EfWrö&¦V7@£°b33c·6fUFôfÆRÒ7G&ærÂvW&RFò6fRFRfÆRæBBb33·2æÖRvFWFVçFöâVrâ3¢b3#¶×Æ7EfWt6öçFVçBçGB£°b33c¶46V6²Ò&ööÆVâÂ6V6²f÷" RFVfVÇBÒfÇ6R£°b33c¶ä6V6²ÒçVÖ&W"Â6öÇVÖâFò6V6²f÷" RÂv6ÖVç26V6¶VBFW26fRFVfVÇBÒgV÷C²gV÷C²£°£²&WGW&âfÇVR2¢öâ7V66W72Ò6fW2FRfÆP£²öâfÇW&RÒæB6WG2W'&÷ £°U%$õ ÒÒfÆR6÷VÆBæ÷B&R7&VFV@£°ÒÒ&ö&VÆÒvF6÷VçFærFRÆ7EfWrFV×0£°Ò"Ò6÷VÆBæ÷Bw&FRFòfÆP£°£²æ÷FR2 æöæP£³ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓФgVæ26fTÆ7EfWrb33c¶Æ7EfWtö&¦V7DæÖRÂb33c·6fUFôfÆRÂb33c¶46V6³ÖfÇ6RÂb33c¶ä6V6³ÒgV÷C²gV÷C² ôfÆT7&VFRb33c·6fUFôfÆR bW'&÷"FVâ 6WDW'&÷"ÄW'&÷" &WGW&â VæD` Æö6Âb33c¶Æ7Eö6÷VçBÒôuT7G&ÄÆ7EfWtvWDFVÔ6÷VçBb33c¶Æ7EfWtö&¦V7DæÖR bW'&÷"FVâ 6WDW'&÷" &WGW&â VæD` Æö6Âb33c·6fT'&³ÒÒ²b33c¶Æ7Eö6÷VçEÐ bb33c¶46V6²FVà f÷"b33c¶ÒFòb33c¶Æ7Eö6÷Vç@ b33c·56VÇGBÒ7G&æu7ÆBôuT7G&ÄÆ7EfWtvWDFVÕFWBb33c¶Æ7EfWtö&¦V7DæÖRÂb33c¶ÒÂb33·Âb33² b33c¶$6V6²Òb33c·56VÇGE²b33c¶ä6V6µÐ 7vF6b33c¶$6V6° 66RgV÷C²gV÷C²ÂgV÷C²gV÷C° ¶æ÷Fæp 66RVÇ6P ·F2æVVG2Fò&RWæFVBFòÆÆ÷rf÷"W6W"FVfæVBvBFò&RFFVBâFVâF26â&R6Æ72à ô'&FBb33c·6fT'&ÂôuT7G&ÄÆ7EfWtvWDFVÕFWBb33c¶Æ7EfWtö&¦V7DæÖRÂb33c¶ÒÃfײgV÷C·ÂgV÷C²f×µôuT7G&ÄÆ7EfWtvWDFVÕFWBb33c¶Æ7EfWtö&¦V7DæÖRÂb33c¶ÒÃfײgV÷C·ÂgV÷C²f×µôuT7G&ÄÆ7EfWtvWDFVÕFWBb33c¶Æ7EfWtö&¦V7DæÖRÂb33c¶ÒÃ" VæE7vF6 æW@ VÇ6P f÷"b33c¶ÒFòb33c¶Æ7Eö6÷Vç@ ô'&FBb33c·6fT'&ÂôuT7G&ÄÆ7EfWtvWDFVÕFWBb33c¶Æ7EfWtö&¦V7DæÖRÂb33c¶Ò æW@ VæD` b33c·w&FRÒôfÆUw&FTg&öÔ'&b33c·6fUFôfÆRÂb33c·6fT'& bW'&÷"FVâ 6WDW'&÷"" &WGW&â VæD`¤VæDgVæ Edited June 29, 2007 by JohnBailey A decision is a powerful thing Link to comment Share on other sites More sharing options...
Mast3rpyr0 Posted June 27, 2007 Share Posted June 27, 2007 Im not 100% sure but maybe you have to open the file for writing before _Filewritefromarray() My UDF's : _INetUpdateCheck() My Programs : GameLauncher vAlpha, InfoCrypt, WindowDesigner, ScreenCap, DailyRemindersPick3GeneratorBackupUtility! Other : Bored? Click Here! Link to comment Share on other sites More sharing options...
JohnBailey Posted June 27, 2007 Author Share Posted June 27, 2007 The function actually does that for you (take a look below). Pretty Cool Thank you though. I'm actually working to change the following part of my script _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1,0)&"|"&_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,1)&"|"&_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,2))oÝ÷ Ù©Ýjëh×6_ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1))oÝ÷ جƥ"0j{më®*mz»hmæë¬zØ^~éܶ*'jw]yÈ{ZµÊ%ºiìïììÛ,j÷~º&¶ËUì«pk+ayû§rب .Ùh¢K(ëax%G+,j÷ËUì4ß©b²Õb{ç-5©Ó~¬j÷ X¥{Múp(^r A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 27, 2007 Author Share Posted June 27, 2007 (edited) Check out how inefficient this is (NOTE: this is not a complete working example. I'm working on one, but it requires a lot of script) expandcollapse popup#include<File.au3> #include<Array.au3> Global $tarray = _ArrayCreate('') _ArrayAdd($tarray,0) _ArrayAdd($tarray,1) _ArrayAdd($tarray,2) _ArrayDelete($tarray,0) saveListView($ListView1,@ScriptDir&"\Daily - test.txt",true,5,$tarray) ;=============================================================================== ; Description: Save ListView Content to a file ; ; Parameter(s): $listViewObjectName - var, the variable name for the ListView Object ; $saveToFile - string, Where to save the file and it's name with extention (eg. C:\myListViewContent.txt) ; $cCheck - boolean, Check for (default = false) ; $nCheck - number, Column to check for , which means checked thus save (default = "") ; ; Return Value(s): On Success - Saves the file ; On Failure - 0 and Sets @Error ; @ERROR - 0 = File could not be created ; - 1 = Probelm with counting the ListView Items ; - 2 = could not write to file ; ; Note(s): none ;=============================================================================== Func saveListView($listViewObjectName,$saveToFile,$cCheck=false,$nCheck="",$hArray='') _FileCreate($saveToFile) If @error Then SetError(0,@error) Return 0 EndIf Local $list_count = _GUICtrlListViewGetItemCount($listViewObjectName) If @error Then SetError(1) Return 0 EndIf Local $saveArray[1] = [$list_count] If $cCheck Then For $i = 1 To $list_count $sSeltxt = StringSplit(_GUICtrlListViewGetItemText($listViewObjectName, $i - 1), '|') $bCheck = $sSeltxt[$nCheck] Switch $bCheck Case "", " " ;nothing Case Else ;this needs to be expanded to allow for scripter to define what to be added. Then this can be a class. If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1,0)&"|"&_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,1)&"|"&_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,2)) Else Local $nArray = _ArrayCreate('') for $nl = 0 to Ubound($hArray)-1 _ArrayAdd($nArray,_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,$hArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 ConsoleWrite('===================<>'&$htotalSize&'<>==================') For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf EndSwitch Next Else For $i = 1 To $list_count _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1)) Next EndIf $write = _FileWriteFromArray($saveToFile, $saveArray, 1) If @error Then SetError(2) Return 0 EndIf EndFunc Edited June 27, 2007 by JohnBailey A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 27, 2007 Author Share Posted June 27, 2007 (edited) Thanks, PsaltyDS and sshrumMODS: Could you move this to Example Scripts and I'll update the first post in this thread with this post.expandcollapse popup;=============================================================================== ; Description: Save ListView Content to a file ; ; Parameter(s): $listViewObjectName - var, the variable name for the ListView Object ; $saveToFile - string, Where to save the file and it's name with extention (eg. C:\myListViewContent.txt) ; $hArray - string or array var, Use to save only certain columns to the output file from the listview (eg. '1,2,3') (default = '') (Note: only use , or | as delimiters) ; $cCheck - boolean, Check for (default = false) ; $nCheck - number, Column to check for , which means checked thus save (default = "") ; ; Return Value(s): On Success - Saves the file ; On Failure - 0 and Sets @Error ; @ERROR - 0 = File could not be created ; - 1 = Probelm with counting the ListView Items ; - 2 = could not write to file ; - 3 = $hArray delimiter used is not , or | ; ; Note(s): none ;=============================================================================== Func saveListView($listViewObjectName,$saveToFile,$hArray='',$cCheck=false,$nCheck="") If $hArray = -1 Then $hArray='' _FileCreate($saveToFile) If @error Then SetError(0,@error) Return 0 EndIf Local $list_count = _GUICtrlListViewGetItemCount($listViewObjectName) If @error Then SetError(1) Return 0 EndIf Local $saveArray[1] = [$list_count] If $cCheck Then For $i = 1 To $list_count $sSeltxt = StringSplit(_GUICtrlListViewGetItemText($listViewObjectName, $i - 1), '|') $bCheck = $sSeltxt[$nCheck] Switch $bCheck Case "", " " ;nothing Case Else If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1)) Else If IsArray($hArray) Then $hhArray = $hArray Else If Number($hArray) = 0 Then If StringInStr($hArray,',') > 0 Then $hhArray = StringSplit($hArray,',') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next ElseIf StringInStr($hArray,'|') > 0 Then $hhArray = StringSplit($hArray,'|') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next Else SetError(3) Return 0 EndIf Else $hhArray = _ArrayCreate($hArray) EndIf EndIf Local $nArray = _ArrayCreate('') for $nl = 0 to Ubound($hhArray)-1 _ArrayAdd($nArray,_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,$hhArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf EndSwitch Next Else For $i = 1 To $list_count If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1)) Else If IsArray($hArray) Then $hhArray = $hArray Else If Number($hArray) = 0 Then If StringInStr($hArray,',') > 0 Then $hhArray = StringSplit($hArray,',') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next ElseIf StringInStr($hArray,'|') > 0 Then $hhArray = StringSplit($hArray,'|') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next Else SetError(3) Return 0 EndIf Else $hhArray = _ArrayCreate($hArray) EndIf EndIf Local $nArray = _ArrayCreate('') for $nl = 0 to Ubound($hhArray)-1 _ArrayAdd($nArray,_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,$hhArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf Next EndIf $write = _FileWriteFromArray($saveToFile, $saveArray, 1) If @error Then SetError(2) Return 0 EndIf Return 1 EndFunc Edited June 27, 2007 by JohnBailey A decision is a powerful thing Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 27, 2007 Share Posted June 27, 2007 No demo script... does it work the way you wanted? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JohnBailey Posted June 27, 2007 Author Share Posted June 27, 2007 No demo script... does it work the way you wanted? oops! Yes, it does indeed work. I will finish the demo script and get that up in a few mins. I didn't know anyone cared about that part. Be back in a min with that script. A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 27, 2007 Author Share Posted June 27, 2007 Here's a working model expandcollapse popup#include<Array.au3> #include <Constants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> #include <File.au3> #include <Misc.au3> Opt ("GUIOnEventMode", 1) $dll = DllOpen("user32.dll") Global Const $WM_NOTIFY = 0x004E ;Thanks GaFrost Global Const $NM_FIRST = 0 ;Thanks GaFrost Global Const $NM_CLICK = ($NM_FIRST - 2) ;Thanks GaFrost Global Const $NM_DBLCLK = ($NM_FIRST - 3) ;Thanks GaFrost #region Parent GUI Setup $ParentWin = GUICreate('Save List Example', 850, 700,-1,-1,$WS_SIZEBOX+$WS_SYSMENU+$WS_MINIMIZEBOX) $SavingNotice = GUICtrlCreateLabel("Saving...", 280, 100, 150, 17) $ListView1 = GUICtrlCreateListView('Name|Phone Number|Location|Use in Special File', 20, 20, 810, 220, $LVS_SHOWSELALWAYS) _GUICtrlListViewSetColumnWidth($ListView1, 0, 260) $tab = GUICtrlCreateTab(20, 250, 810, 180) GUICtrlSetResizing ($tab,$GUI_DOCKAUTO) GUICtrlCreateTabItem("Edit") $SaveEditsBtn = GUICtrlCreateButton('Save Changes', 370, 290, 80, 24) GUICtrlSetResizing (-1,$GUI_DOCKSIZE) GUICtrlCreateLabel("Account Name:", 30, 295) $editAccountName = GUICtrlCreateInput("", 130, 292, 200, 20) GUICtrlCreateLabel("Account Number:", 30, 325) $editAccountNumber = GUICtrlCreateInput("", 130, 322, 200, 20) GUICtrlCreateLabel("Default Folder:", 30, 355) $editAccountLocation = GUICtrlCreateInput("", 130, 352, 200, 20) $editDate = GUICtrlCreateDate("", 130, 390, 200, 20) $UseinSpecialFileCH = GUICtrlCreateCheckbox("Use in Special File", 375, 330, 120, 17) GUICtrlCreateTabItem("") GUICtrlSetResizing (-1,$GUI_DOCKSIZE) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") ;Thanks GaFrost GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUICtrlSetOnEvent($UseinSpecialFileCH, "ButtonPress") GUICtrlSetOnEvent($SaveEditsBtn, "ButtonPress") GUISetState() #endregion Parent GUI Setup list(@ScriptDir&'\test6-DB.txt',$ListView1) While 1 Sleep(10) If _IsPressed("1B", $dll) Then If WinActive($ParentWin) = 1 Then Terminate() EndIf EndIf WEnd Func list($db, $list) Local $array If Not _FileReadToArray($db, $array) Then MsgBox(4096, "Error", "Edit "&$db &" Error reading log to Array error:" & @error) EndIf For $i = 1 To $array[0] GUICtrlCreateListViewItem($array[$i], $list) Next EndFunc ;==>list #region Button Presses Func ButtonPress() Switch @GUI_CTRLID Case $UseinSpecialFileCH $selected = _GUICtrlListViewGetCurSel($ListView1) If BitAND(GUICtrlRead(@GUI_CTRLID), $GUI_CHECKED) = $GUI_CHECKED Then _GUICtrlListViewSetItemText($ListView1, $selected, 3, "") Else _GUICtrlListViewSetItemText($ListView1, $selected, 3, " ") EndIf Case $SaveEditsBtn Local $selectedAmount = _GUICtrlListViewGetSelectedCount($ListView1) If $selectedAmount > 1 Then MsgBox(0, "Multiple Items Selected", "You have selected: " & $selectedAmount & " items. Only one Item may be selected to make this change.") Else $selected = _GUICtrlListViewGetCurSel($ListView1) _GUICtrlListViewSetItemText($ListView1, $selected, 0, GUICtrlRead($editAccountName)) SavePressed() EndIf EndSwitch EndFunc #endregion Button Presses ; ;Saving function Func SavePressed() GUISetState(@SW_DISABLE, $ParentWin) GUICtrlSetState($SavingNotice,$GUI_SHOW) GUICtrlSetState($ListView1,$GUI_HIDE) saveListView($ListView1,@ScriptDir&'\test6-DB.txt') saveListView($ListView1,@ScriptDir&"\test6-DB-SpecialFile.txt",'0,1,2',true,4) GUICtrlSetState($SavingNotice,$GUI_HIDE) GUICtrlSetState($ListView1,$GUI_SHOW) GUISetState(@SW_ENABLE, $ParentWin) EndFunc Func SpecialEvents() Select Case @GUI_CTRLID = $GUI_EVENT_CLOSE Terminate() Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE ;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) WinSetState($ParentWin, "", @SW_HIDE) TrayTip(@ScriptName, "has been minimzed. Doubleclick here to restore", 10, 0) Case @GUI_CTRLID = $GUI_EVENT_RESTORE MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) EndSelect EndFunc ;thanks GaFrost!! Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView1 Select Case $event = $NM_CLICK ;ConsoleWrite(_GUICtrlListViewGetItemText($ListView1)&@CRLF) $seltxt = StringSplit(_GUICtrlListViewGetItemText($ListView1), '|') If UBound($seltxt) - 1 = 4 Then GUICtrlSetData($editAccountName, $seltxt[1]) GUICtrlSetData($editAccountNumber, $seltxt[2]) GUICtrlSetData($editAccountLocation, $seltxt[3]) Switch $seltxt[4] Case " ","" GUICtrlSetState($UseinSpecialFileCH,$GUI_Unchecked) Case Else GUICtrlSetState($UseinSpecialFileCH,$GUI_Checked) EndSwitch EndIf EndSelect EndSelect $tagNMHDR = 0 $event = 0 $lParam = 0 Return $GUI_RUNDEFMSG EndFunc ;==>WM_Notify_Events Func Terminate() DllClose($dll) Exit EndFunc ;=============================================================================== ; Description: Save ListView Content to a file ; ; Parameter(s): $listViewObjectName - var, the variable name for the ListView Object ; $saveToFile - string, Where to save the file and it's name with extention (eg. C:\myListViewContent.txt) ; $hArray - string or array var, Use to save only certain columns to the output file from the listview (eg. '1,2,3') (default = '') (Note: only use , or | as delimiters) ; $cCheck - boolean, Check for (default = false) ; $nCheck - number, Column to check for , which means checked thus save (default = "") ; ; Return Value(s): On Success - Saves the file ; On Failure - 0 and Sets @Error ; @ERROR - 0 = File could not be created ; - 1 = Probelm with counting the ListView Items ; - 2 = could not write to file ; - 3 = $hArray delimiter used is not , or | ; ; Note(s): none ;=============================================================================== Func saveListView($listViewObjectName,$saveToFile,$hArray='',$cCheck=false,$nCheck="") If $hArray = -1 Then $hArray='' _FileCreate($saveToFile) If @error Then SetError(0,@error) Return 0 EndIf Local $list_count = _GUICtrlListViewGetItemCount($listViewObjectName) If @error Then SetError(1) Return 0 EndIf Local $saveArray[1] = [$list_count] If $cCheck Then For $i = 1 To $list_count $sSeltxt = StringSplit(_GUICtrlListViewGetItemText($listViewObjectName, $i - 1), '|') $bCheck = $sSeltxt[$nCheck] Switch $bCheck Case "", " " ;nothing Case Else If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1)) Else If IsArray($hArray) Then $hhArray = $hArray Else If Number($hArray) = 0 Then If StringInStr($hArray,',') > 0 Then $hhArray = StringSplit($hArray,',') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next ElseIf StringInStr($hArray,'|') > 0 Then $hhArray = StringSplit($hArray,'|') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next Else SetError(3) Return 0 EndIf Else $hhArray = _ArrayCreate($hArray) EndIf EndIf Local $nArray = _ArrayCreate('') for $nl = 0 to Ubound($hhArray)-1 _ArrayAdd($nArray,_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,$hhArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf EndSwitch Next Else For $i = 1 To $list_count If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListViewGetItemText($listViewObjectName, $i - 1)) Else If IsArray($hArray) Then $hhArray = $hArray Else If Number($hArray) = 0 Then If StringInStr($hArray,',') > 0 Then $hhArray = StringSplit($hArray,',') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next ElseIf StringInStr($hArray,'|') > 0 Then $hhArray = StringSplit($hArray,'|') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next Else SetError(3) Return 0 EndIf Else $hhArray = _ArrayCreate($hArray) EndIf EndIf Local $nArray = _ArrayCreate('') for $nl = 0 to Ubound($hhArray)-1 _ArrayAdd($nArray,_GUICtrlListViewGetItemText($listViewObjectName, $i - 1,$hhArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf Next EndIf $write = _FileWriteFromArray($saveToFile, $saveArray, 1) If @error Then SetError(2) Return 0 EndIf Return 1 EndFunc The Demo DB file Joseph Moore|156-479-156|USA| Sue Orde|356-789-216|England| Paul Frue|11566-156-586|Canada| George McPhisee|126-489-894|USA| A decision is a powerful thing Link to comment Share on other sites More sharing options...
NassauSky Posted March 11, 2015 Share Posted March 11, 2015 This is an old post. The first thread posted code is corrupted but is duplicated in thread 5 without the corruption. The main reason I'm bumping this thread is to give you an alternative with updated code. A couple of the functions in the code are outdated. Here is the updated version of the code: expandcollapse popup_GUICtrlListView_GetItemTextFunc saveListView($listViewObjectName,$saveToFile,$hArray='',$cCheck=false,$nCheck="") If $hArray = -1 Then $hArray='' _FileCreate($saveToFile) If @error Then SetError(0,@error) Return 0 EndIf Local $list_count = _GUICtrlListView_GetItemCount($listViewObjectName) If @error Then SetError(1) Return 0 EndIf Local $saveArray[1] = [$list_count] If $cCheck Then For $i = 1 To $list_count $sSeltxt = StringSplit(_GUICtrlListView_GetItemText($listViewObjectName, $i - 1), '|') $bCheck = $sSeltxt[$nCheck] Switch $bCheck Case "", " " ;nothing Case Else If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListView_GetItemText($listViewObjectName, $i - 1)) Else If IsArray($hArray) Then $hhArray = $hArray Else If Number($hArray) = 0 Then If StringInStr($hArray,',') > 0 Then $hhArray = StringSplit($hArray,',') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next ElseIf StringInStr($hArray,'|') > 0 Then $hhArray = StringSplit($hArray,'|') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next Else SetError(3) Return 0 EndIf Else ReDim $hhArray[$hArray];Previously was $hhArray = _ArrayCreate($hArray) EndIf EndIf Local $nArray = [];Previously was $nArray = _ArrayCreate('') for $nl = 0 to Ubound($hhArray)-1 _ArrayAdd($nArray,_GUICtrlListView_GetItemText($listViewObjectName, $i - 1,$hhArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf EndSwitch Next Else For $i = 1 To $list_count If $hArray = '' Then _ArrayAdd($saveArray, _GUICtrlListView_GetItemText($listViewObjectName, $i - 1)) Else If IsArray($hArray) Then $hhArray = $hArray Else If Number($hArray) = 0 Then If StringInStr($hArray,',') > 0 Then $hhArray = StringSplit($hArray,',') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next ElseIf StringInStr($hArray,'|') > 0 Then $hhArray = StringSplit($hArray,'|') _ArrayDelete($hhArray,0) for $nnl = 0 to UBound($hhArray)-1 $hhArray[$nnl] = StringStripWS($hhArray[$nnl],8) next Else SetError(3) Return 0 EndIf Else ReDim $hhArray[$hArray];Previously was $hhArray = _ArrayCreate($hArray) EndIf EndIf Local $nArray = [];Previously was $nArray = _ArrayCreate('') for $nl = 0 to Ubound($hhArray)-1 _ArrayAdd($nArray,_GUICtrlListView_GetItemText($listViewObjectName, $i - 1,$hhArray[$nl])) next Local $hlinetoAdd = '' Local $htotalSize = Ubound($nArray)-1 For $nl = 1 to $htotalSize If $nl <> $htotalSize Then $hlinetoAdd &= $nArray[$nl]&'|' Else $hlinetoAdd &= $nArray[$nl] EndIf Next _ArrayAdd($saveArray,$hlinetoAdd) EndIf Next EndIf $write = _FileWriteFromArray($saveToFile, $saveArray, 1) If @error Then SetError(2) Return 0 EndIf Return 1 EndFunc 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