Sign in to follow this  
Followers 0
ScriptedIT

Get variables from a dynamic $TVS_CHECKBOXES

4 posts in this topic

I love AutoIT and am just starting to get into the GUI and makes some tools after years of using the basic to raise access and just get the job done.

I finally got a gui that dynamically shows a list of directories with checkboxes. It works well but I cant get back the selected directories. I need one of two things back Just the directories that where selected or all directories and if they where selected. I see info on $TVS_CHECKBOXES and getting info from them but the examples never created them dynamically.

Also it does not work with a path like \\server\share but it will work with a mapped drive like Z: (I can always use autoit to map the drive so no biggy). This is my first post so forgive and advise on any edicate issues. Thanks to all and thanks for AutoIT getting the job done like no other tool in the space. Note there is a obviously incorrect attempt to get back a variable but it is static and I assume the information is in an array. It returns nothing. Part code borrowed from the non-checkboxed tree view demo.

#include <GUIConstants.au3>

#include <GuiTreeView.au3>

Opt("MustDeclareVars", 1)

Dim $h_GUI, $Msg, $treeview, $h_search, $s_file, $h_item, $strPath, $item, $text, $gobutton, $Input, $Label

$strPath = "z:\"

$h_GUI = GUICreate("Scripted IT Applications Installer", 320, 450)

$treeview = GUICtrlCreateTreeView(10, 10, 300, 400, $TVS_CHECKBOXES)

$gobutton = GUICtrlCreateButton("&Go", 10, 420, 70, 20)

GUISetState()

$h_search = FileFindFirstFile($strPath & "*.*")

If $h_search <> -1 Then

While 1

$s_file = FileFindNextFile($h_search)

If @error Then ExitLoop

If Not StringInStr(FileGetAttrib($strPath & $s_file), "D") Then ContinueLoop

$h_item = _GUICtrlTreeViewInsertItem($treeview, $s_file)

WEnd

EndIf

While 1

$Msg = GUIGetMsg()

Select

Case $Msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $gobutton

$item = GUICtrlRead($treeview) ; Get the controlID of the current selected treeview item

If $item = 0 Then

MsgBox(64, "Demo", "No item currently selected")

Else

$text = GUICtrlRead($item, 1) ; Get the text of the treeview item

If $text == "" Then

MsgBox(16, "Error", "Error while retrieving infos about item")

Else

MsgBox(64, "TreeView Demo", "Current item selected is: " & $text) ; $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item

EndIf

EndIf

EndSelect

WEnd

Exit

Share this post


Link to post
Share on other sites



I love AutoIT and am just starting to get into the GUI and makes some tools after years of using the basic to raise access and just get the job done.

I finally got a gui that dynamically shows a list of directories with checkboxes. It works well but I cant get back the selected directories. I need one of two things back Just the directories that where selected or all directories and if they where selected. I see info on $TVS_CHECKBOXES and getting info from them but the examples never created them dynamically.

Also it does not work with a path like \\server\share but it will work with a mapped drive like Z: (I can always use autoit to map the drive so no biggy). This is my first post so forgive and advise on any edicate issues. Thanks to all and thanks for AutoIT getting the job done like no other tool in the space. Note there is a obviously incorrect attempt to get back a variable but it is static and I assume the information is in an array. It returns nothing. Part code borrowed from the non-checkboxed tree view demo.

#include <GUIConstants.au3>

#include <GuiTreeView.au3>

Opt("MustDeclareVars", 1)

Dim $h_GUI, $Msg, $treeview, $h_search, $s_file, $h_item, $strPath, $item, $text, $gobutton, $Input, $Label

$strPath = "z:\"

$h_GUI = GUICreate("Scripted IT Applications Installer", 320, 450)

$treeview = GUICtrlCreateTreeView(10, 10, 300, 400, $TVS_CHECKBOXES)

$gobutton = GUICtrlCreateButton("&Go", 10, 420, 70, 20)

GUISetState()

$h_search = FileFindFirstFile($strPath & "*.*")

If $h_search <> -1 Then

While 1

$s_file = FileFindNextFile($h_search)

If @error Then ExitLoop

If Not StringInStr(FileGetAttrib($strPath & $s_file), "D") Then ContinueLoop

$h_item = _GUICtrlTreeViewInsertItem($treeview, $s_file)

WEnd

EndIf

While 1

$Msg = GUIGetMsg()

Select

Case $Msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $gobutton

$item = GUICtrlRead($treeview) ; Get the controlID of the current selected treeview item

If $item = 0 Then

MsgBox(64, "Demo", "No item currently selected")

Else

$text = GUICtrlRead($item, 1) ; Get the text of the treeview item

If $text == "" Then

MsgBox(16, "Error", "Error while retrieving infos about item")

Else

MsgBox(64, "TreeView Demo", "Current item selected is: " & $text) ; $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item

EndIf

EndIf

EndSelect

WEnd

Exit

If you replace this line

$h_item = _GUICtrlTreeViewInsertItem($treeview, $s_file)

with

GUICtrlCreateTreeViewitem($s_file,$treeview)

does it do what you wany?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks Martin there are two several things I want to do

One is to for each folder run a file in it (always with the same name)

"Folder\setup.exe"

That would be a wrapper for an application install for example (so you choose from the directory of applications which ones to install on that machine).

I will also use it at some later point to replace files in the selected directories (or values in a given file) for example setup.ini used by the wrapper.

If you replace this line

$h_item = _GUICtrlTreeViewInsertItem($treeview, $s_file)

with

GUICtrlCreateTreeViewitem($s_file,$treeview)

does it do what you wany?

Share this post


Link to post
Share on other sites

Wow it was so close. It does return the lowest option selected. Any hints on returning each of the selected items (as in more than the last one). I take it being a static variables read last come only searved. I imagine I need to define each line as an entry in a variable or create an array based on selected variables.

Anyway you have certainly progressed me to getting something! I'll keep digging to get the others unless your feeling that special newbie good will I get in my areas at times <G>.

BT

If you replace this line

$h_item = _GUICtrlTreeViewInsertItem($treeview, $s_file)

with

GUICtrlCreateTreeViewitem($s_file,$treeview)

does it do what you wany?

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