Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Input From User
#1
Hello, I am a new user of your program and find it very useful. I have a problem which I can't seem to find a solution. Below is what my boss needs to accomplish.

We are using a program where the user can select up to 6 buttons. The buttons have an id starting at 201, 202, all the way to 206. Each button does different things. At the moment, the user changes the actual macro to only select specific buttons. This is where the problem starts. I have tried using inp- command but I think I need something better or additional error checking. Here are the steps I would like to accomplish.

1. Prompt the user where they can enter the button id. For example: 201, 204, 206. Separated by commas. I am pretty sure the string can be parsed and turn it into numeric variables after the prompt.

2. Error checking, make sure the entered information matches the 6 buttons.

3. Then let macro run only the codes under those selected buttons 3x. for example:

rep 3
,;code 201
,mes "buttom 1 selected"

,;code 204
,mes "buttom 2 selected"

,;code 206
,mes "buttom 6 selected"


I hope I am making this clear. LOL.

Thank you for all your help.
#2
You can use custom dialog. Example:

Code:
Copy      Help
\Dialog_Editor

str controls = "3"
str lb3
lb3="Button1[]Button2[]Button3[]Button4[]Button5[]Button6"
if(!ShowDialog(_s.getmacro(getopt(itemid) 1) 0 &controls win)) ret

rep 3
,if(lb3[0]='1')
,,mes "Button1"
,if(lb3[1]='1')
,,mes "Button2"
,if(lb3[2]='1')
,,mes "Button3"
,if(lb3[3]='1')
,,mes "Button4"
,if(lb3[4]='1')
,,mes "Button5"
,if(lb3[5]='1')
,,mes "Button6"

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 105 86 "Form"
;1 Button 0x54030001 0x4 4 68 48 14 "OK"
;2 Button 0x54030000 0x4 54 68 48 14 "Cancel"
;3 ListBox 0x54230109 0x200 4 4 98 61 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010500 "*" ""
#3
Am I suppose to do anything special to your example other than copying and pasting it to my macro?

I have not use the dialog editor feature before.

Thanks
#4
Replace Dialog4 to the name of macro where you will paste this code. You can also replace Button1 etc to whatever you like.

To paste in QM, use menu Edit -> Other formats -> Paste escaped.
#5
I must be doing something wrong. I created a new macro to match Dialog4, pasted the codes and gave me an error message when I played it.

It said:
Error (RT) in Dialog4: can't create dialog



When I press F2, it brings me to this line:
if(!ShowDialog("Dialog4" 0 &controls win)) ret




Thank you very much!
#6
Ok, I changed the above macro so that it would work without editing.
#7
Thanks so much!
#8
I am getting an error message "Can't create dialog" when I encrypt the file.

What can I try to fix this?
#9
It is because ShowDialog cannot decrypt dialog definition. Place dialog definition in other macro and leave it nonencrypted.

Example:

Macro1 (can be encrypted):

Code:
Copy      Help
str controls = "3"
str lb3
lb3="Button1[]Button2[]Button3[]Button4[]Button5[]Button6"
if(!ShowDialog("Macro2" 0 &controls win)) ret

rep 3
,if(lb3[0]='1')
,,mes "Button1"
,if(lb3[1]='1')
,,mes "Button2"
,if(lb3[2]='1')
,,mes "Button3"
,if(lb3[3]='1')
,,mes "Button4"
,if(lb3[4]='1')
,,mes "Button5"
,if(lb3[5]='1')
,,mes "Button6"

Macro2 (must not be encrypted):

Code:
Copy      Help
;\Dialog_Editor

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 105 86 "Form"
;1 Button 0x54030001 0x4 4 68 48 14 "OK"
;2 Button 0x54030000 0x4 54 68 48 14 "Cancel"
;3 ListBox 0x54230109 0x200 4 4 98 61 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010500 "*" ""

Note: first argument of ShowDialog must be name of macro that contains dialog definition.


Alternatively, you can pass dialog definition itself instead of macro name. Use flag 2 with ShowDialog.

Example:

Code:
Copy      Help
\Dialog_Editor

str dd=
;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 105 86 "Form"
;1 Button 0x54030001 0x4 4 68 48 14 "OK"
;2 Button 0x54030000 0x4 54 68 48 14 "Cancel"
;3 ListBox 0x54230109 0x200 4 4 98 61 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010500 "*" ""


str controls = "3"
str lb3
lb3="Button1[]Button2[]Button3[]Button4[]Button5[]Button6"
if(!ShowDialog(dd 0 &controls 0 2)) ret

rep 3
,if(lb3[0]='1')
,,mes "Button1"
,if(lb3[1]='1')
,,mes "Button2"
,if(lb3[2]='1')
,,mes "Button3"
,if(lb3[3]='1')
,,mes "Button4"
,if(lb3[4]='1')
,,mes "Button5"
,if(lb3[5]='1')
,,mes "Button6"


Forum Jump:


Users browsing this thread: 3 Guest(s)