Jump to content

Edit a list of items! _ListEditbox.au3


ShminkyBoy
 Share

Recommended Posts

I'm doing some different things with listboxes and buttons, thought I'd throw this out there in case someone else has as much fun as i did:

#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <Constants.au3>
#include <array.au3>
Opt("GUIDataSeparatorChar","|") ;"|" is the default

$csv_String="one|two|three|four"
$as_Array=StringSplit($csv_String, "|", 1)

$csv_string=_ListEditbox($as_Array,"New Title")


        MsgBox(0x41040, "Result", $csv_string)

Exit

;~ This function edits arrays of data using a listbox
;~ $as_List = a one dimensional array of data (required)
;~ $s_Title = the name you want to appear in the window (optional)
;~ $n_width = the width of the edit box (optional)
;~ $n_height = the hieght of the editbox (optional)
;~
;~ @error 0: returns the edited array ByRef; the return value is the edited array as a delimited string
;~ @error 1: returns the original array ByRef; the return value is the original array as a delimited string
Func _ListEditbox(ByRef $as_List, $s_Title="Edit List Items", $n_width=288, $n_height=256)
    if $n_width<288 then $n_width = 288
    if $n_height<256 then $n_height = 256
;~  Get the vars to edit
    $csv_List = ""
    for $x = 1 to $as_List[0]
        If $csv_List = "" Then
            $csv_List=$as_List[$x]
        Else
            $csv_List=$csv_List & "|" & $as_List[$x]
        EndIf
    next
    $csv_EditList = $csv_List
    $as_EditList = $as_List
    $n_EntryIndex = 0
;~ Make the edit box and buttons
    $id_EditWindow=GUICreate($s_Title,$n_width,$n_height,@DesktopWidth/2-$n_width/2, @DesktopHeight/2-$n_height/2,$WS_DLGFRAME,$WS_EX_TOPMOST)
    $id_AddEntry=GUICtrlCreateButton ("Add", 16,16,72,24)
    $id_DeleteEntry=GUICtrlCreateButton ("Delete",16,64,72,24)
    $id_ClearList=GUICtrlCreateButton ("Clear", 16,96,72,24)
    $id_Done=GUICtrlCreateButton ("Done", 16, 160,72,24)
    $id_Cancel=GUICtrlCreateButton ("Cancel", 16,192,72,24)
    $id_InputBox = GUICtrlCreateInput ("", 108,16,$n_width-124,24)
    $id_ListBox=GUICtrlCreateList ("", 108,64,$n_width-124,$N_HEIGHT-96,$WS_VSCROLL)
    GUICtrlSetLimit(-1,200) ; to limit horizontal scrolling 
;~ Enumerate the listbox with the server list
    GUICtrlSetData($id_listbox,$csv_EditList)
    GUISetState ()
;~ Edit the item list
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE then $msg = $id_Cancel
        If $msg = $id_InputBox then $msg = $id_AddEntry
        Select
            case $msg = $id_AddEntry
                $NewEntry = GUICtrlRead($id_InputBox)
                if $NewEntry <> "" then
                    GUICtrlSetData($id_InputBox,"")
                    $as_EditList[0] = $as_EditList[0] + 1
                    Redim $as_EditList[$as_EditList[0]+1]
                    $as_EditList[$as_EditList[0]] = $NewEntry
                    If $csv_EditList = "" Then
                        $csv_EditList=$as_EditList[$as_EditList[0]]
                    Else
                        $csv_EditList=$csv_EditList & "|" & $as_EditList[$as_EditList[0]]
                    EndIf
                    GUICtrlSetData($id_ListBox,"")
                    GUICtrlSetData($id_ListBox,$csv_EditList)
                Else
                endif
            case $msg = $id_DeleteEntry
                $n_EntryIndex=_GUICtrlListBox_GetCurSel($id_listbox)+1
                If $n_EntryIndex > 0 Then
                    _ArrayDelete( $as_EditList,$n_EntryIndex)
                    $as_EditList[0]=$as_EditList[0]-1
                    $csv_EditList = ""
                    for $x = 1 to $as_EditList[0]
                        If $csv_EditList = "" Then
                            $csv_EditList=$as_EditList[$x]
                        Else
                            $csv_EditList=$csv_EditList & "|" & $as_EditList[$x]
                        EndIf
                    next
                    GUICtrlSetData($id_ListBox,"")
                    GUICtrlSetData($id_ListBox,$csv_EditList)
                Else
                EndIf
            case $msg = $id_ClearList
                $answer = MsgBox(0x41021, $s_Title, "Are you sure you want to clear the list?")
                If $answer = 1 Then
                    $csv_EditList=""
                    For $x = 1 To $as_EditList[0]
                        $as_EditList[$x] = ""
                    Next
                    $as_EditList[0]=0
                    GUICtrlSetData($id_listbox,$csv_EditList)
                Else
                EndIf
            Case $msg = $id_Done
                $csv_List=$csv_EditList
                $as_List=$as_EditList
                $csv_EditList=""
                For $x = 1 To $as_EditList[0]
                    $as_EditList[$x] = ""
                Next
                $as_EditList[0]=0
                    GUISetState (@SW_HIDE,$id_editwindow)
                SetError(0)
                return $csv_List
            Case $msg = $id_Cancel
                GUISetState (@SW_HIDE,$id_editwindow)
                SetError(1)
                return $csv_List
        EndSelect
    Wend
EndFunc
Link to comment
Share on other sites

Graphical User Interface (GUI) Help and Support

Find support for the GUI creation features of AutoIt here.

It's pretty cool! :)

As this is more an example, rather than a request for support, a mod will probably move it later... :)

Link to comment
Share on other sites

yeah, I'm finding that I'm not allowed to post there yet for some reason

:shrugs:

thanks for the good words though =)

You need to have 10 posts min... Should have noticed that. Sorry... :) Edited by Bert
Link to comment
Share on other sites

Hi

10; i just get

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Programs\SearchEngine\funlistbox.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

+>21:29:33 Starting AutoIt3Wrapper v.1.9.5.6 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X86)

>Running AU3Check (1.54.10.0) from:C:\Program Files\AutoIt3

C:\Programs\SearchEngine\funlistbox.au3(76,68) : ERROR: _GUICtrlListBox_GetCurSel(): undefined function.

$n_EntryIndex=_GUICtrlListBox_GetCurSel($id_listbox)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Programs\SearchEngine\funlistbox.au3 - 1 error(s), 0 warning(s)

!>21:29:35 AU3Check ended.rc:2

>Exit code: 0 Time: 7.314

v 11; well.

Randall

Link to comment
Share on other sites

I'm using the latest and I don't get an error... :)

Edit: Not the latest... My bad. I'm using 3.2.10.0... Wonder why... lol. Thought I was on the latest!

Edited by Bert
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...