Jump to content

GUICtrlCreateList, multiple adding of items


NELyon
 Share

Recommended Posts

Well, I'm officially starting programming in Autoit again. My last UDF was just to get me going, and now I'm embarking on my first real project in over 6 Months.

So the problem is, I'm creating a Favorites manager. It runs from a file based database, and each entry is RC4 encrypted. So, here's my problem.

It reads from a file, Favorites.ftf, which is a file with the string "Favorites List" as the first line, and RC4 encrypted URLs as each line below. The problem is, the "Favorites List" entry gets added onto the list 2 or 3 times. The other entries appear fine.

#Include <GUIConstants.au3>
#Include <File.au3>
#Include <String.au3>
Global $favs
;Start by checking if the program has ran before
If Not FileExists(@ScriptDir & "\Favorites.ftf") Then
    MsgBox(0, "Favoritizer", "This is either the first time running this program" & @CRLF & " Or you have deleted your definition file. A new one will be created")
    FileWrite(@ScriptDir & "\Favorites.ftf", "Favorites List" & @CRLF)
EndIf

$hGUI = GUICreate("Favoritizer 0.1 by Senton-Bomb", 500, 500)
$Msg = GUICtrlCreateLabel("Welcome to Favoritizer! An easy-to-use Favorites organizer.", 0, 0)
$bLoadDef = GUICtrlCreateButton("lReoad Favorites", 15, 450, 100)
$ListOfDefs = GUICtrlCreateList("", 5, 100, 300, 300)
$bNewDef = GUICtrlCreateButton("New Favorite", 180, 450, 100)
GUISetState()

_FileReadToArray(@ScriptDir & "\Favorites.ftf", $favs)
For $i = 2 To $favs[0]
    $dcrpt = _StringEncrypt(0, $favs[$i], "autoitistehpwn")
    $str = $favs[1] & "|" & $dcrpt
    GUICtrlSetData($ListOfDefs, $str)
Next

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $bLoadDef
            _FileReadToArray(@ScriptDir & "\Favorites.ftf", $favs)
            GUICtrlSetData($ListOfDefs, "")
            For $i = 2 To $favs[0]
                $dcrpt = _StringEncrypt(0, $favs[$i], "autoitistehpwn") 
                $str = $favs[1] & "|" & $dcrpt
                GUICtrlSetData($ListOfDefs, $str)
            Next


        Case $bNewDef
            $tobe = InputBox("Favoritizer", "Enter a URL or file name to become a favorite", "http://autoitscript.com/forum")
            $ntobe = _StringEncrypt(1, $tobe, "autoitistehpwn")
            FileWrite(@ScriptDir & "\Favorites.ftf", $ntobe & @CRLF)
        Case Else
            Sleep(2)
    EndSwitch
WEnd


Func _Exit()
    GUIDelete($hGUI)
    MsgBox(0, "Favoritizer", "Thank you for using Favoritizer!")
    Exit
EndFunc   ;==>_Exit

My OS is NimbleX Linux, emulating Windows 2000 on Autoit v3.2.10.0.

Can anybody help me?

Link to comment
Share on other sites

  • 3 weeks later...

Ok, i'm having a different problem now.

I tried adding in a filter to remove any blank entries from the array (From the @CRLF when writing)

The filter works, but it's broken my list updater. I get an 'Array variable has incorrect number of subscripts or subscript dimension range exceeded.: ' error.

Here's my updated code:

#include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>
#include <Array.au3>
Global $favs
;Start by checking if the program has ran before
If Not FileExists(@ScriptDir & "\Favorites.ftf") Then
    MsgBox(0, "Favoritizer", "This is either the first time running this program" & @CRLF & " Or you have deleted your definition file. A new one will be created")
    FileWrite(@ScriptDir & "\Favorites.ftf", "")
EndIf

$hGUI = GUICreate("Favoritizer 0.1 by Senton-Bomb", 500, 500)
$Msg = GUICtrlCreateLabel("Welcome to Favoritizer! An easy-to-use Favorites organizer.", 0, 0)
$bLoadDef = GUICtrlCreateButton("Reload Favorites", 15, 450, 100)
$ListOfDefs = GUICtrlCreateList("", 5, 100, 300, 300)
$bNewDef = GUICtrlCreateButton("New Favorite", 180, 450, 100)
ControlFocus("", "", $Msg)
GUISetState()

_FileReadToArray(@ScriptDir & "\Favorites.ftf", $favs)
For $z = 0 to $favs[0]
    If $favs[$z] = "" Then
        _ArrayDelete($favs,  $z)
    EndIf
Next


;~ _ArrayDisplay($favs)
;~ Exit
ControlFocus("", "", $ListOfDefs)

For $i = 1 To $favs[0]
    $dcrpt = _StringEncrypt(0, $favs[$i], "autoitistehpwn")
    $str = $dcrpt
    GUICtrlSetData($ListOfDefs, $str & "|")
Next

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $bLoadDef
            _FileReadToArray(@ScriptDir & "\Favorites.ftf", $favs)
            ControlFocus("", "", $ListOfDefs)
            GUICtrlSetData($ListOfDefs, "")
            For $i = 1 To $favs[0]
                $dcrpt = _StringEncrypt(0, $favs[$i], "autoitistehpwn")
                $str = $dcrpt
                GUICtrlSetData($ListOfDefs, $str)
            Next
        Case $bNewDef
            $tobe = InputBox("Favoritizer", "Enter a URL or file name to become a favorite", "http://autoitscript.com/forum")
            $ntobe = _StringEncrypt(1, $tobe, "autoitistehpwn")
            FileWrite(@ScriptDir & "\Favorites.ftf", $ntobe & @CRLF)
        Case Else
            Sleep(2)
    EndSwitch
WEnd


Func _Exit()
    GUIDelete($hGUI)
    MsgBox(0, "Favoritizer", "Thank you for using Favoritizer!")
    Exit
EndFunc  ;==>_Exit

If you uncomment the _ArrayDisplay, you will see that the array displays fine. It has 2 elements, and the second element is the first line in the file, which in my case is:

Favoritizer.ftf:

692DB7AD55E1993A9FF773E71AF7A4A309A90990051B3908DF7EAF6FD60D84CEA80F9502A1A2F2DE724259E5D298F0642A98

7D442B9E767C084B

(Which is http://autoitscript.com/forum encrypted with the password "autoitistehpwn")

Does anyone know what's wrong?

Link to comment
Share on other sites

Hi,

Use 3.2.11.0?

I think there was a bug in arraydelete empty arrays before?.....

_ArrayDisplay($favs,"UBound($favs)="&UBound($favs))
;~ Exit
ControlFocus("", "", $ListOfDefs)

For $i = 1 To UBound($favs)-1
;~ For $i = 1 To $favs[0]

Best, randall

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...