l3ill Posted September 22, 2016 Posted September 22, 2016 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 22, 2016 Author Posted September 22, 2016 Hey Bill Sorry to bother you again Do you know why, if I remove all items in the list and close, it doesn't save the changes. If I leave 1 item be and close, then it works. So, when I remove all items, and display the array, it still thinks that there is 1 item.
l3ill Posted September 22, 2016 Posted September 22, 2016 Just a quick stab because I'm on my way out the door.. 1 item lends to think it may be a Ubound failure when parsing the array for instance: first element in the array is the number of elements. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
l3ill Posted September 22, 2016 Posted September 22, 2016 (edited) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _FileWriteFromArray($File, $aContent) If @error Then MsgBox(0,"", @error) ;this $error check is giving me: 5 - Start index is greater than the $iUbound parameter EndIf ExitLoop On my way out again... will look again later if you haven't found it yourself by then... p.s. it only spits this error when you delete all entries... Edited September 22, 2016 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 23, 2016 Author Posted September 23, 2016 Bill, Perfect mate, now I was able to solve it. It might be a dirty fix, but it works Case $GUI_EVENT_CLOSE $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _FileWriteFromArray($IgnoreFile,$aContent) ;this $error check returns 5 - Start index is greater than the $iUbound parameter ;So if the list is empty, it returns error 5 If @error = 5 Then $FileOpenFile = FileOpen($File, 2) FileWrite($FileOpenFile, "") FileClose($FileOpenFile) EndIf ExitLoop
l3ill Posted September 23, 2016 Posted September 23, 2016 I'm all about "whatever works" But could you post your updated code in its entirety? I would like to have a look at that array issue, maybe we can find a more elegant fix My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 23, 2016 Author Posted September 23, 2016 Sure thing expandcollapse popup;______________________________________________ #include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> #include <File.au3> #include <AD.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> ;______________________________________________ Global $MainGUI_ManageUserList Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") Global $fullname = "" Call ("MainGUI_ManageUserList") Func MainGUI_ManageUserList() Local $cAddUser $MainGUI_ManageUserList = GUICreate("Manage User List", 800, 800, -1, -1) $cLV = GUICtrlCreateListView("[Users]", 10, 10, 400, 775) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $cAddUser = GUICtrlCreateButton("Add User", 425, 10, 80, 30) $cRemoveUser = GUICtrlCreateButton("Remove User", 425, 50, 80, 30) GUISetState(@SW_SHOW, $MainGUI_ManageUserList) ; Intialise ListView Global $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _FileWriteFromArray($File,$aContent) ;this $error check returns 5 - Start index is greater than the $iUbound parameter ;So if the list is empty, it returns error 5 If @error = 5 Then $FileOpenFile = FileOpen($File, 2) FileWrite($FileOpenFile, "") FileClose($FileOpenFile) EndIf ExitLoop Case $cAddUser ;Saves changes to the txt file (Maybe a user has been removed from the list) $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _FileWriteFromArray($File,$aContent) ;this $error check returns 5 - Start index is greater than the $iUbound parameter ;So if the list is empty, it returns error 5 If @error = 5 Then $FileOpenFile = FileOpen($File, 2) FileWrite($FileOpenFile, "") FileClose($FileOpenFile) EndIf GUISetState(@SW_DISABLE, $MainGUI_ManageUserList) $ChildGUI_AddUser = ChildGUI_AddUser() GUISetState(@SW_ENABLE, $MainGUI_ManageUserList) GUIDelete($ChildGUI_AddUser) ; WinActivate($MainGUI_ManageUserList) ; <<<<< Activate the ParentGUI again. Case $cRemoveUser _GUIListViewEx_Delete() EndSwitch WEnd EndFunc ;==>Main Func ChildGUI_AddUser() #Region ### START Koda GUI section ### Form= $ChildGUI_AddUser = GUICreate("Find User", 416, 170, -1, -1) GUISetBkColor(0xFFFFFF) $inputboxUsername = GUICtrlCreateInput("", 16, 53, 145, 29) GUICtrlSetFont(-1, 12, 400, 0, "@Arial Unicode MS") $Search = GUICtrlCreateButton("Search", 176, 53, 65, 29) GUICtrlSetFont(-1, 10, 400, 0, "@Arial Unicode MS") $Cancel = GUICtrlCreateButton("Cancel", 314, 48, 81, 33) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") $OK = GUICtrlCreateButton("OK", 314, 8, 81, 33) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") $Label1 = GUICtrlCreateLabel("Type in username and click Search", 16, 8, 209, 22) GUICtrlSetFont(-1, 10, 400, 0, "@Arial Unicode MS") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $Search $ReadinputboxUsername = GUICtrlRead($inputboxUsername) _AD_Open() $fullname = _AD_GetObjectAttribute($ReadinputboxUsername, "name") _AD_Close() If $fullname = "" Then MsgBox(0,"Error","No user is found") Else $FullNameLabel = GUICtrlCreateLabel($fullname, 54, 104, 328, 36) GUICtrlSetFont(-1, 18, 400, 0, "@Arial Unicode MS") EndIf Case $Cancel ExitLoop Case $OK $ReadinputboxUsername = GUICtrlRead($inputboxUsername) $FileOpen = FileOpen($File, 0) $Read = FileRead($FileOpen) $StringToFind = $ReadinputboxUsername If $ReadinputboxUsername = "" Then MsgBox(0,"Error", "No user is chosen") ElseIf $fullname = "" Then MsgBox(0,"Error", "No user is chosen") ElseIf StringRegExp($Read, $StringToFind) Then MsgBox(0, "Info", "User " & $StringToFind & " is already on the User List") FileClose($FileOpen) Else ;Adds the user at the top in the list _GUIListViewEx_InsertSpec( 1, $ReadinputboxUsername, $ReadinputboxUsername) ;Saves changes to the txt file $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _FileWriteFromArray($File,$aContent) ExitLoop EndIf EndSwitch WEnd Return $ChildGUI_AddUser EndFunc ;==>ChildGUI_AddUser
l3ill Posted September 25, 2016 Posted September 25, 2016 Weird problem.... After testing/playing with this for a while It seems as though _FileWriteFromArray is having trouble writing (only) the [0] element. with that knowledge I then found this: https://www.autoitscript.com/trac/autoit/ticket/2242 But this was four years ago... Maybe someone else has some input? My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 26, 2016 Author Posted September 26, 2016 Yep it seems like an old bug, that still exists in AutoIt. At least with the error check, I was able to make that work around. So thanks for that
l3ill Posted September 26, 2016 Posted September 26, 2016 No problem... My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
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