Jump to content

add/remove from txt file inside GUI


david1337
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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 by l3ill
Link to comment
Share on other sites

Bill,

Perfect mate, now I was able to solve it.
It might be a dirty fix, but it works :P

 

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

 

Link to comment
Share on other sites

Sure thing :)

 

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

 

Link to comment
Share on other sites

:'( 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?

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...