Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Execute the selected item in turn
#1
Hello,

I want to execute the selected item in turn, for example, I chose, item 1 3 5, When I press the ok button,

will execute the sub-function 1 3 5, the dialog is minimized, not closed

In addition, I want to know how to get the text of the selected item. The current output is all numbers, like this 10101

Thanks in advance



Macro Execute the selected item
Code:
Copy      Help
str L=
;;sub.m1
;;sub.m2
;;sub.m3
;;sub.m4
;;sub.m5

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "5"
str lb5
lb5=L
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

out
out lb5




#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub m1

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m1" "" m)


#sub m2

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m2" "" m)


#sub m3

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m3" "" m)


#sub m4

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m4" "" m)


#sub m5

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m5" "" m)
#2
I changed the smart dialog box to a simple dialog box, which can achieve the effect I want, but it is very troublesome, is there a simpler method? I want to use smart dialogs, any suggestions for perfecting this feature code are welcome. Smile


Macro Macro2
Code:
Copy      Help
;start
str L=
;;sub.m1
;;sub.m2
;;sub.m3
;;sub.m4
;;sub.m5

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "5"
str lb5
lb5=L
if(!ShowDialog(dd 0 &controls)) ret

out
out lb5

if lb5=10000
,sub.m1

if lb5=11000
,sub.m1
,sub.m2
,
if lb5=11100
,sub.m1
,sub.m2
,sub.m3
,
goto start

;#sub DlgProc
;function# hDlg message wParam lParam
;
;sel message
,;case WM_INITDIALOG
,;case WM_DESTROY
,;case WM_COMMAND goto messages2
;ret
;;messages2
;sel wParam
,;case IDOK
,;min hDlg
,;ret 0
,;case IDCANCEL
;ret 1

#sub m1

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m1" "" m)


#sub m2

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m2" "" m)


#sub m3

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m3" "" m)


#sub m4

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m4" "" m)


#sub m5

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m5" "" m)

The above method is not reliable. If I re-add the list item, the operation of executing the code should be re-modified.  Sad
#3
Can someone give some advice?   Smile

The number of items in the list is not fixed, and new items need to be added later.

How to deal with is the best way  Confused
#4
Function Function_LB_multiSelect_Dialog
Code:
Copy      Help
ARRAY(str)- lb_selected
str L=
;;sub.m1
;;sub.m2
;;sub.m3
;;sub.m4
;;sub.m5

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;3 Button 0x54032000 0x0 9 116 56 14 "Run Selected"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "5"
str lb5
lb5=L
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
out
lb5=lb_selected
out lb5

#sub DlgProc v
function# hDlg message wParam lParam
int hlb
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
hlb=id(5 hDlg)
sel wParam
,case IDOK
,LB_GetSelectedItems(hlb 0 lb_selected)
,case IDCANCEL
,case 3 ;;Run Selected
,LB_GetSelectedItems(hlb 0 lb_selected)
,_s=lb_selected
,str ss
,foreach ss _s
,,ss.trim
,,opt waitmsg 1
,,sel ss
,,,case "sub.m1"
,,,sub.m1
,,,case "sub.m2"    
,,,sub.m2
,,,case "sub.m3"
,,,sub.m3
,,,case "sub.m4"
,,,sub.m4
,,,case "sub.m5"
,,,sub.m5
ret 1

#sub m1

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m1" "" m)


#sub m2

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m2" "" m)


#sub m3

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m3" "" m)


#sub m4

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m4" "" m)


#sub m5

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m5" "" m)

need this function as well

Function LB_GetSelectedItems
Code:
Copy      Help
;/
function# hwnd [ARRAY(int)&ai] [ARRAY(str)&as]

;Gets selected items in a multisel listbox control.
;Returns number of selected items.

;hwnd - control handle.
;ai - array variable that receives indices of selected items. Optional, can be 0.
;as - array variable that receives text of selected items. Optional, can be 0.

;REMARKS
;The control must belong to current process. Use eg in dialog procedures.


if(&ai) ai=0
if(&as) as=0

int i n
n=SendMessage(hwnd LB_GETSELCOUNT 0 0); if(n<1) ret
if &ai or &as
,ARRAY(int) _ai; if(!&ai) &ai=_ai
,ai.create(n)
,n=SendMessage(hwnd LB_GETSELITEMS n &ai[0]); if(n<0) n=0
,if(n!ai.len) ai.redim(n)
,if &as
,,as.create(n)
,,for(i 0 n) LB_GetItemText(hwnd ai[i] as[i])
ret n
#5
Prompt without this function

why Huh

My QM software does not have these functions.

and this
http://www.quickmacros.com/forum/showthr...9#pid33199


Attached Files Image(s)
   
#6
sorry i forgot to post it .It is also posted in the forum  somewhere and is also in the archive updated post above with the needed function
#7
Still prompted error


Attached Files Image(s)
   
#8
restart qm and see if it errors again
#9
Still errors
#10
you must not be using full posted code
#11
Do you mean that the code I copied is incomplete?

I am sure that the code is complete and I tried it many times.
#12
I installed win10 virtual machine and QM on my computer.
Test the above code, there are still errors
Huh
#13
got me on why it will not work is unicode mode enabled in qm?



   


try this version

Function dialogMultisellistbox
Code:
Copy      Help
ARRAY(str)- lb_selected
str l=
;;sub.m1
;;sub.m2
;;sub.m3
;;sub.m4
;;sub.m5

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;3 Button 0x54032000 0x0 9 116 56 14 "Run Selected"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "5"
str lb5
lb5=l
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
out
lb5=lb_selected
out lb5

#sub DlgProc v
function# hDlg message wParam lParam
int hlb
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
hlb=id(5 hDlg)
sel wParam
,case IDOK
,sub.LB_GetSelectedItems2(hlb lb_selected)
,case IDCANCEL
,case 3 ;;Run Selected
,sub.LB_GetSelectedItems2(hlb lb_selected)
,_s=lb_selected
,str ss
,foreach ss _s
,,ss.trim
,,opt waitmsg 1
,,sel ss
,,,case "sub.m1"
,,,sub.m1
,,,case "sub.m2"    
,,,sub.m2
,,,case "sub.m3"
,,,sub.m3
,,,case "sub.m4"
,,,sub.m4
,,,case "sub.m5"
,,,sub.m5
ret 1

#sub m1

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m1" "" m)


#sub m2

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m2" "" m)


#sub m3

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m3" "" m)


#sub m4

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m4" "" m)


#sub m5

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m5" "" m)

#sub LB_GetSelectedItems2
function hlb ARRAY(str)&a

;Gets text of selected items in a multiple-selection listbox.


int i n=SendMessage(hlb LB_GETSELCOUNT 0 0)
if(n=-1) ;;single-sel control
,a.redim(1)
,if(LB_SelectedItem(hlb a[0])<0) a.redim
else
,a.redim(n)
,if(n)
,,ARRAY(int) selitems.create(n)
,,SendMessage(hlb LB_GETSELITEMS n &selitems[0])
,,for(i 0 n) LB_GetItemText hlb selitems[i] a[i]
#14
The above code is running successfully  Smile

I have been enabling unicode


The function you use is not the original function?

Your original function is more powerful and can get two values.

Is it impossible to use it?
Huh

When I click the OK button, the dialog closes. How can I not close the dialog? Only use the X in the upper right corner


Attached Files Image(s)
   
#15
no the function in the second version is slightly different

try the 1st function again and comment out this line first

if(&as) as=0
#16
Still not working

I found the following separate code,


Function LB_GetSelectedItemsIndexArray
Code:
Copy      Help
[size=large];/ http://www.quickmacros.com/forum/showthread.php?tid=408&pid=17235#pid17235
function hlb ARRAY(int)&selitems

;Gets integer array of selected items 0-based index in a multiple-selection listbox.


int i n=SendMessage(hlb LB_GETSELCOUNT 0 0)
if(n)
,selitems.create(n)
,SendMessage(hlb LB_GETSELITEMS n &selitems[0])[/size]


Attached Files Image(s)
   
#17
How to stop the task when I press the ctrl+d hotkey   Huh

Macro Macro3
Code:
Copy      Help
ARRAY(str)- lb_selected
str l=
;&sub.m1
;sub.m2
;&sub.m3
;sub.m4
;&sub.m5

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;5 ListBox 0x54230109 0x200 64 16 96 86 ""
;3 Button 0x54032000 0x0 9 116 56 14 "Run Selected"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "5"
str lb5
lb5=l
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
out
lb5=lb_selected
out lb5

#sub DlgProc v
function# hDlg message wParam lParam
int hlb
sel message
,case WM_INITDIALOG
,DT_SetAccelerators(hDlg "400 Cd")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
hlb=id(5 hDlg)
sel wParam
,case IDOK
,sub.LB_GetSelectedItems2(hlb lb_selected)
,
,case IDCANCEL
,
,case 400 ;;stop
,res hDlg
,;stop code:
,
,case 3 ;;Run Selected
,min hDlg
,sub.LB_GetSelectedItems2(hlb lb_selected)
,_s=lb_selected
,str ss
,foreach ss _s
,,ss.trim
,,opt waitmsg 1
,,sel ss
,,,case "sub.m1"
,,,sub.m1
,,,case "sub.m2"
,,,sub.m2
,,,case "sub.m3"
,,,sub.m3
,,,case "sub.m4"
,,,sub.m4
,,,case "sub.m5"
,,,sub.m5
,res hDlg
ret 1

#sub m1

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m1" "" m)


#sub m2

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m2" "" m)


#sub m3

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m3" "" m)


#sub m4

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m4" "" m)


#sub m5

MES m.timeout=5; m.style="OCa"; m.default='C'
mes("this is m5" "" m)

#sub LB_GetSelectedItems2
function hlb ARRAY(str)&a

;Gets text of selected items in a multiple-selection listbox.


int i n=SendMessage(hlb LB_GETSELCOUNT 0 0)
if(n=-1) ;;single-sel control
,a.redim(1)
,if(LB_SelectedItem(hlb a[0])<0) a.redim
else
,a.redim(n)
,if(n)
,,ARRAY(int) selitems.create(n)
,,SendMessage(hlb LB_GETSELITEMS n &selitems[0])
,,for(i 0 n) LB_GetItemText hlb selitems[i] a[i]
#18
Now I have a problem,

In the process of executing sequentially, any sub-function has a problem, the dialog box will be closed 
Huh

is there a simple exception handling method? 

Also, sometimes I need to use a hotkey to terminate execution 


Forum Jump:


Users browsing this thread: 1 Guest(s)