Sign in to follow this  
Followers 0
samonlinesuper

How to make listbox items run

8 posts in this topic

Dear all,

I created below GUI and wants to have the select items to RUN while the "RUN" button is pressed. I already tried a lots of ways but failed, could anyone help me, thank you.

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <GUIListBox.au3>

#include <WindowsConstants.au3>

#include <Array.au3>

Global $aItem[6][2] = [[5,""],["Upgrade/Downloadgrade,0],["Item2",0],["Item3",0],["Item4",0],["Item5",0]]

$DualListDlg = GUICreate("Choices Dialog", 751, 514, 247, 156)

GUISetIcon("", -1)

$ListBox1 = GUICtrlCreateList("", 8, 8, 305, 227, BitOR($GUI_SS_DEFAULT_LIST,$LBS_MULTIPLESEL))

$Button1 = GUICtrlCreateButton(">", 332, 15, 31, 25)

$Button2 = GUICtrlCreateButton(">>", 332, 48, 31, 25)

$Button3 = GUICtrlCreateButton("<", 332, 81, 31, 25)

;GUICtrlSetState(-1, $GUI_DISABLE)

$Button4 = GUICtrlCreateButton("<<", 332, 114, 31, 25)

$ListBox2 = GUICtrlCreateList("", 384, 8, 331, 227, $LBS_MULTIPLESEL)

$Button5 = GUICtrlCreateButton("&RUN", 112, 273, 75, 25)

$Button6 = GUICtrlCreateButton("&CLOSE", 192, 273, 75, 25)

; $Button7 = GUICtrlCreateButton("&Help", 272, 273, 75, 25)

GUISetState(@SW_SHOW)

Update_Listviews()

While 1

$msg = GUIGetMsg()

Switch $msg

Case $Button1

Shift($ListBox1, 1)

Update_Listviews()

Case $Button3

Shift($ListBox2, 0)

Update_Listviews()

Case $Button6, $GUI_EVENT_CLOSE

ExitLoop

EndSwitch

WEnd

Func Update_Listviews() ; scan array and reload listboxes accordingly

Local $str1, $str2

For $x = 1 to $aItem[0][0] ; loop through array

If $aItem[$x][1] Then ; if 1, add to right listbox string

$str2 &= $aItem[$x][0] & "|"

Else ; if 0, add to left listbox string

$str1 &= $aItem[$x][0] & "|"

EndIf

Next

GUICtrlSetData($ListBox1, "")

GUICtrlSetData($ListBox1, StringTrimRight($str1, 1)) ; strip trailing "|" and load to left listbox

GUICtrlSetData($ListBox2, "")

GUICtrlSetData($ListBox2, StringTrimRight($str2, 1)) ; strip trailing "|" and load to right listbox

EndFunc

Func Shift($control, $dest)

Local $row = 0

For $x = 1 to $aItem[0][0] ; loop through array

If $aItem[$x][1] <> $dest Then ; is array element not already in dest listbox?

If _GUICtrlListBox_GetSel($control, $row) Then $aItem[$x][1] = $dest ; if row selected , move array element

$row += 1

EndIf

Next

EndFunc

Share this post


Link to post
Share on other sites



I don`t know what you mean with "RUN" the list items. Please use the Code or AutoIt forum tags to post code it much nicer.

[AUTOIT][/AUTOIT] --------> ] Here the code [

Share this post


Link to post
Share on other sites

Dears,

Sorry, I am new in this forum and AutoIT.

I don't know what you mean about to past the code but anyway, the code is like below:

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <GUIListBox.au3>

#include <WindowsConstants.au3>

#include <Array.au3>

Global $aItem[6][2] = [[5,""],["Upgrade/Downloadgrade,0],["Item2",0],["Item3",0],["Item4",0],["Item5",0]]

$DualListDlg = GUICreate("Choices Dialog", 751, 514, 247, 156)

GUISetIcon("", -1)

$ListBox1 = GUICtrlCreateList("", 8, 8, 305, 227, BitOR($GUI_SS_DEFAULT_LIST,$LBS_MULTIPLESEL))

$Button1 = GUICtrlCreateButton(">", 332, 15, 31, 25)

$Button2 = GUICtrlCreateButton(">>", 332, 48, 31, 25)

$Button3 = GUICtrlCreateButton("<", 332, 81, 31, 25)

;GUICtrlSetState(-1, $GUI_DISABLE)

$Button4 = GUICtrlCreateButton("<<", 332, 114, 31, 25)

$ListBox2 = GUICtrlCreateList("", 384, 8, 331, 227, $LBS_MULTIPLESEL)

$Button5 = GUICtrlCreateButton("&RUN", 112, 273, 75, 25)

$Button6 = GUICtrlCreateButton("&CLOSE", 192, 273, 75, 25)

; $Button7 = GUICtrlCreateButton("&Help", 272, 273, 75, 25)

GUISetState(@SW_SHOW)

Update_Listviews()

While 1

$msg = GUIGetMsg()

Switch $msg

Case $Button1

Shift($ListBox1, 1)

Update_Listviews()

Case $Button3

Shift($ListBox2, 0)

Update_Listviews()

Case $Button6, $GUI_EVENT_CLOSE

ExitLoop

EndSwitch

WEnd

Func Update_Listviews() ; scan array and reload listboxes accordingly

Local $str1, $str2

For $x = 1 to $aItem[0][0] ; loop through array

If $aItem[$x][1] Then ; if 1, add to right listbox string

$str2 &= $aItem[$x][0] & "|"

Else ; if 0, add to left listbox string

$str1 &= $aItem[$x][0] & "|"

EndIf

Next

GUICtrlSetData($ListBox1, "")

GUICtrlSetData($ListBox1, StringTrimRight($str1, 1)) ; strip trailing "|" and load to left listbox

GUICtrlSetData($ListBox2, "")

GUICtrlSetData($ListBox2, StringTrimRight($str2, 1)) ; strip trailing "|" and load to right listbox

EndFunc

Func Shift($control, $dest)

Local $row = 0

For $x = 1 to $aItem[0][0] ; loop through array

If $aItem[$x][1] <> $dest Then ; is array element not already in dest listbox?

If _GUICtrlListBox_GetSel($control, $row) Then $aItem[$x][1] = $dest ; if row selected , move array element

$row += 1

EndIf

Next

EndFunc

The "RUN" means to "Execute".

What I did now is to create Menu list and have the items select from left then press ">" button to right listbox. After that, I can press "RUN" to "execute" those items in the Right listbox. Thank you for helping.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Put [AUT0IT] in top of your code, and [/AUT0IT] below your code here in forum posts. Then your code looks much better:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Global $aItem[6][2] = [[5,""],["Upgrade/Downloadgrade,0],["Item2",0],["Item3",0],["Item4",0],["Item5",0]]
$DualListDlg = GUICreate("Choices Dialog", 751, 514, 247, 156)
GUISetIcon("", -1)
$ListBox1 = GUICtrlCreateList("", 8, 8, 305, 227, BitOR($GUI_SS_DEFAULT_LIST,$LBS_MULTIPLESEL))
$Button1 = GUICtrlCreateButton(">", 332, 15, 31, 25)
$Button2 = GUICtrlCreateButton(">>", 332, 48, 31, 25)
$Button3 = GUICtrlCreateButton("<", 332, 81, 31, 25)
;GUICtrlSetState(-1, $GUI_DISABLE)
$Button4 = GUICtrlCreateButton("<<", 332, 114, 31, 25)
$ListBox2 = GUICtrlCreateList("", 384, 8, 331, 227, $LBS_MULTIPLESEL)
$Button5 = GUICtrlCreateButton("&RUN", 112, 273, 75, 25)
$Button6 = GUICtrlCreateButton("&CLOSE", 192, 273, 75, 25)
; $Button7 = GUICtrlCreateButton("&Help", 272, 273, 75, 25)
GUISetState(@SW_SHOW)
Update_Listviews()
While 1
$msg = GUIGetMsg()
Switch $msg
Case $Button1
Shift($ListBox1, 1)
Update_Listviews()
Case $Button3
Shift($ListBox2, 0)
Update_Listviews()
Case $Button6, $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Func Update_Listviews() ; scan array and reload listboxes accordingly
Local $str1, $str2
For $x = 1 to $aItem[0][0] ; loop through array
If $aItem[$x][1] Then ; if 1, add to right listbox string
$str2 &= $aItem[$x][0] & "|"
Else ; if 0, add to left listbox string
$str1 &= $aItem[$x][0] & "|"
EndIf
Next
GUICtrlSetData($ListBox1, "")
GUICtrlSetData($ListBox1, StringTrimRight($str1, 1)) ; strip trailing "|" and load to left listbox
GUICtrlSetData($ListBox2, "")
GUICtrlSetData($ListBox2, StringTrimRight($str2, 1)) ; strip trailing "|" and load to right listbox
EndFunc
Func Shift($control, $dest)
Local $row = 0
For $x = 1 to $aItem[0][0] ; loop through array
If $aItem[$x][1] <> $dest Then ; is array element not already in dest listbox?
If _GUICtrlListBox_GetSel($control, $row) Then $aItem[$x][1] = $dest ; if row selected , move array element
$row += 1
EndIf
Next
EndFunc

Execute the Items? What shall happen when executing "Upgrade/Downloadgrade"?

A-Jay

Edited by ajag

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites

When pressed then "Upgrade/Downgrade" item will start to do the upgrade process (By the way, this upgrade/download is for the "smart device" not for windows itself), thank you.

Share this post


Link to post
Share on other sites

What upgrade process? please explain it in details.

Share this post


Link to post
Share on other sites

Thanks,

Me too I just learned this - [Autoit]

And please can anyone help me with the post I made @ General Help and Support

Thank You.

Share this post


Link to post
Share on other sites

Upgrade process means that if smart device (such as Cisco switch so on) has loaded firmware with version 1.1xxx, and I want to use the script to change the loaded or upgrade to version 1.2xxx. That is what the Upgrade process means, thank you.

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