Sign in to follow this  
Followers 0
Tiger

Array Help

5 posts in this topic

I have a little script. that search tools from a list.

So that is my problem

Array:

Col 1 Col2

Mozilla Firefox | ID from Listviewitem

How can I write in the array the id in the function "_load_toollist"

Opt("GUIOnEventMode", 1)

#include <File.au3>
#include <GUIConstants.au3>
#include <GUITreeview.au3>

GUICreate("Select tools", 260, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
$TreeView = GUICtrlCreateTreeView(20, 20, 220, 310, $TVS_CHECKBOXES)
Call("_load_toollist")
GUICtrlCreateButton("&Cancel", 20, 350, 100, 30)
GUICtrlCreateButton("&OK", 140, 350, 100, 30)
GUISetState(@SW_SHOW)

Func _load_toollist()
    _GUICtrlTreeViewDeleteAllItems($TreeView)
    Local $tool[1]
    Dim $tools
    _FileReadToArray(@ScriptDir & "\list.txt", $tools)
    For $x = 1 To UBound($tools) - 1
        $id = GUICtrlCreateTreeViewItem($tools[$x], $TreeView)
        ReDim $tool[UBound($tool) + 1]
        $tool[0] = $tool[0] + 1
        $tool[UBound($tool) - 1] = $tools[$x]
    Next
EndFunc   ;==>_load_toollist
Func _close()
    Exit
EndFunc   ;==>_close

While 1 
    sleep(500)
WEnd

Toollist

Mozilla Firefox


My UDFs:- _RegEnumKey

Share this post


Link to post
Share on other sites



When you create the $tools array with _FileReadToArray(), $tools[0] already is set to the count, so all the Ubound and ReDim action is unnecessary:

Opt("GUIOnEventMode", 1)

#include <File.au3>
#include <GUIConstants.au3>
#include <GUITreeview.au3>
#include <array.au3> ; only for _ArrayDisplay()

Global $TreeView, $tool, $tools

GUICreate("Select tools", 260, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
$TreeView = GUICtrlCreateTreeView(20, 20, 220, 310, $TVS_CHECKBOXES)
_load_toollist()
GUICtrlCreateButton("&Cancel", 20, 350, 100, 30)
GUICtrlSetOnEvent(-1, "_close")
GUICtrlCreateButton("&OK", 140, 350, 100, 30)
GUICtrlSetOnEvent(-1, "_OK_Button")
GUISetState(@SW_SHOW)

While 1
    Sleep(500)
WEnd

Func _load_toollist()
    _GUICtrlTreeViewDeleteAllItems($TreeView)
    _FileReadToArray(@ScriptDir & "\list.txt", $tools)
    Global $tool[$tools[0] + 1] = [$tools[0]]
    For $x = 1 To $tools[0]
        $tool[$x] = GUICtrlCreateTreeViewItem($tools[$x], $TreeView)
    Next
EndFunc   ;==>_load_toollist

Func _OK_Button()
    _ArrayDisplay($tools, "Debug: $tools")
    _ArrayDisplay($tool, "Debug: $tool")
EndFunc

Func _close()
    Exit
EndFunc   ;==>_close

:)


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

Share this post


Link to post
Share on other sites

Thanks, but I will write the ID of listviewitem in the array, too. In Col 1 the name of the tool and in col 2 the id of the listviewitem


My UDFs:- _RegEnumKey

Share this post


Link to post
Share on other sites

Thanks, but I will write the ID of listviewitem in the array, too. In Col 1 the name of the tool and in col 2 the id of the listviewitem

Well, there is no ListView in your GUI, just a TreeView, but the code I posted gets all the information into two 1D arrays, so once you create the ListView control, adding the items will just be:

Opt("GUIOnEventMode", 1)

#include <File.au3>
#include <GUIConstants.au3>
#include <GUITreeview.au3>
#include <array.au3> ; only for _ArrayDisplay()

Global $TreeView, $ListView, $tool, $tools

GUICreate("Select tools", 260, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
$TreeView = GUICtrlCreateTreeView(20, 20, 220, 200, $TVS_CHECKBOXES)
_load_toollist()
$ListView = GUICtrlCreateListView("Tool|CtrlID", 20, 230, 220, 120)
_GUICtrlListViewSetColumnWidth(-1, 0, 110)
GUICtrlCreateButton("&Cancel", 20, 360, 100, 30)
GUICtrlSetOnEvent(-1, "_close")
GUICtrlCreateButton("&OK", 140, 360, 100, 30)
GUICtrlSetOnEvent(-1, "_load_listview")
GUISetState(@SW_SHOW)

While 1
    Sleep(500)
WEnd

Func _load_toollist()
    _GUICtrlTreeViewDeleteAllItems($TreeView)
    _FileReadToArray(@ScriptDir & "\list.txt", $tools)
    Global $tool[$tools[0] + 1] = [$tools[0]]
    For $x = 1 To $tools[0]
        $tool[$x] = GUICtrlCreateTreeViewItem($tools[$x], $TreeView)
    Next
EndFunc   ;==>_load_toollist

Func _load_listview()
    _GUICtrlListViewDeleteAllItems($ListView)
    For $x = 1 To $tools[0]
        GUICtrlCreateListViewItem($tools[$x] & "|" & $tool[$x], $ListView)
    Next
EndFunc   ;==>_load_listview

Func _close()
    Exit
EndFunc   ;==>_close

:)


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

Share this post


Link to post
Share on other sites

Sorry. I have write the script:

Opt("GUIOnEventMode", 1)

#include <Array.au3>
#include <File.au3>
#include <GUIConstants.au3>
#include <GUITreeview.au3>

Dim $tools

GUICreate("Select tools", 260, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
$TreeView = GUICtrlCreateTreeView(20, 20, 220, 310, $TVS_CHECKBOXES)
Call("_load_toollist")
GUICtrlCreateButton("&Cancel", 20, 350, 100, 30)
GUICtrlSetOnEvent(-1, "_close")
GUICtrlCreateButton("&OK", 140, 350, 100, 30)
GUICtrlSetOnEvent(-1, "_ok")

GUISetState(@SW_SHOW)

Func _load_toollist()
    _GUICtrlTreeViewDeleteAllItems($TreeView)
    Local $tmp_array[1][2]
    _FileReadToArray(@ScriptDir & "\liste.txt", $tools)
    If UBound($tools, 0) = 1 Then
        ReDim $tmp_array[UBound($tools)][2]
        For $i = 1 To UBound($tools) - 1
            $tmp_array[$i][0] = $tools[$i]
            $tmp_array[$i][1] = GUICtrlCreateTreeViewItem($tools[$i], $TreeView)
        Next
        $tools = $tmp_array
    EndIf
    _ArrayDisplay($tools)
EndFunc   ;==>_load_toollist

Func _ok()
    For $x = 1 To _GUICtrlTreeViewGetCount($TreeView)
        If BitAND(GUICtrlRead($tools[$x][1]), $GUI_CHECKED) Then ; selected
            $name = $tools[$x][0]
            MsgBox(0, "Tool " & $x, $name & " is selected")
        EndIf
    Next
EndFunc   ;==>_ok

Func _close()
    Exit
EndFunc   ;==>_close

While 1 
    sleep(500)
WEnd

My UDFs:- _RegEnumKey

Share this post


Link to post
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
Sign in to follow this  
Followers 0