Generating MSButton base on variable
Moderators: JRL, Dorian (MJT support)
Generating MSButton base on variable
Hello All,
I just wondering that are we able to add the MSButton into a dialog automatically as soon as the variable is set?
Let say if I set the variable to 1 then one MSButton is created...
Thanks for your help.
I just wondering that are we able to add the MSButton into a dialog automatically as soon as the variable is set?
Let say if I set the variable to 1 then one MSButton is created...
Thanks for your help.
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Generating MSButton base on variable
You need to use the include> command and dynamically create a .scp file with the dialog code. That code can then be created as you please.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Generating MSButton base on variable
I would NOT dynamically change the dialog definition. Instead ALWAYS have a button but simply show/hide it based on value of your variable.
To do this set the button's "Visible" property at runtime with SetDialogProperty
To do this set the button's "Visible" property at runtime with SetDialogProperty
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Generating MSButton base on variable
Am I doing something really bad when I do this to generate an unknown number of buttons on the fly? I do it to open files that are fetched from a folder structure. Click button to open folder or a file...Marcus Tettmar wrote: ↑Wed Feb 05, 2020 3:44 pmI would NOT dynamically change the dialog definition. Instead ALWAYS have a button but simply show/hide it based on value of your variable.
To do this set the button's "Visible" property at runtime with SetDialogProperty
Re: Generating MSButton base on variable
I agreed cause I don't know the number of buttons that need to be shown on the dialog. I can change the size of dialog base on the number of "clicking" the button and I would like to show the button that represent the info that I did. I know I can create a bunch of buttons and set visible to false but just wanted to know is there anyway to dynamically create them and the code will be easier to manage.
Hi Grovekillen,
Can you tell me more about the idea to include a macro to create a button? How to do that and where to place that macro?
All the buttons need to be shown on one dialog though. So I create a dialog and write a code to create a button?
Thanks
Hi Grovekillen,
Can you tell me more about the idea to include a macro to create a button? How to do that and where to place that macro?
All the buttons need to be shown on one dialog though. So I create a dialog and write a code to create a button?
Thanks
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Generating MSButton base on variable
A demo for you...nodochau wrote: ↑Thu Feb 06, 2020 11:11 amI agreed cause I don't know the number of buttons that need to be shown on the dialog. I can change the size of dialog base on the number of "clicking" the button and I would like to show the button that represent the info that I did. I know I can create a bunch of buttons and set visible to false but just wanted to know is there anyway to dynamically create them and the code will be easier to manage.
Hi Grovekillen,
Can you tell me more about the idea to include a macro to create a button? How to do that and where to place that macro?
All the buttons need to be shown on one dialog though. So I create a dialog and write a code to create a button?
Thanks
Code: Select all
Let>DIALOG_HEIGHT=300
Let>DIALOG_WIDTH=600
Let>BUTTON_HEIGHT=25
Let>BUTTON_WIDTH=75
Let>NUMBER_OF_BUTTONS=40
Let>BUTTON_CODE=
Let>k=-1
Let>c=0
Let>r=-1
Repeat>k
Let>k=k+1
Let>BUTTON_POS_X={(%c%)*%BUTTON_WIDTH%}
Let>BUTTON_POS_Y={(%r%)*%BUTTON_HEIGHT%}
Let>BUTTON_CAPTION=%k%:%c%:%r%
LabelToVar>dialog_button,TEMP,1,0
ConCat>BUTTON_CODE,TEMP
Let>TEST_HEIGHT={(%r%+1)*%BUTTON_HEIGHT%/%DIALOG_HEIGHT%}
If>TEST_HEIGHT<1
Let>r=r+1
Else>
Let>r=0
Let>c=c+1
Endif>
Let>TEST_WIDTH={%c%*%BUTTON_WIDTH%/%DIALOG_WIDTH%}
If>TEST_WIDTH>1
Let>k=NUMBER_OF_BUTTONS
Endif>
Until>k=NUMBER_OF_BUTTONS
StringReplace>BUTTON_CODE,*/,,BUTTON_CODE
LabelToVar>dialog_base,DIALOG_CODE,1,0,*/
DeleteFile>%SCRIPT_DIR%\temp.scp
WriteLn>%SCRIPT_DIR%\temp.scp,,DIALOG_CODE
Include>%SCRIPT_DIR%\temp.scp
//DeleteFile>%SCRIPT_DIR%\temp.scp
Show>Dialog1
wait>10
Exit>
/*
dialog_base:
Dialog>Dialog1
object Dialog1: TForm
ClientHeight = %DIALOG_HEIGHT%
ClientWidth = %DIALOG_WIDTH%
%BUTTON_CODE%end
EndDialog>Dialog1
*/
/*
dialog_button:
object MSButton%k%: tMSButton
Left = %BUTTON_POS_X%
Top = %BUTTON_POS_Y%
Width = %BUTTON_WIDTH%
Height = %BUTTON_HEIGHT%
Caption = '%BUTTON_CAPTION%'
end*/
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Generating MSButton base on variable
@Dev:
I found a bug when I created this demo script.
Will not work:
Will work:
I found a bug when I created this demo script.
Will not work:
Code: Select all
Let>k=0
Repeat>k
Let>k=k+1
LabelToVar>test,TEMP,1,0,*/
Until>k=10
/*
test:
This is a test
*/
Code: Select all
Let>k=0
Repeat>k
Let>k=k+1
LabelToVar>test,TEMP,1,0
Until>k=10
/*
test:
This is a test
*/
Re: Generating MSButton base on variable
Thanks Grovkillen,
I will try it today.
I will try it today.