Generating MSButton base on variable

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
nodochau
Pro Scripter
Posts: 131
Joined: Wed Jan 16, 2019 12:59 pm

Generating MSButton base on variable

Post by nodochau » Wed Feb 05, 2020 1:27 pm

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.

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Generating MSButton base on variable

Post by Grovkillen » Wed Feb 05, 2020 2:45 pm

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.
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Generating MSButton base on variable

Post by Marcus Tettmar » Wed Feb 05, 2020 3:44 pm

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
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Generating MSButton base on variable

Post by Grovkillen » Wed Feb 05, 2020 6:01 pm

Marcus Tettmar wrote:
Wed Feb 05, 2020 3:44 pm
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
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...
Let>ME=%Script%

Running: 15.0.24
version history

nodochau
Pro Scripter
Posts: 131
Joined: Wed Jan 16, 2019 12:59 pm

Re: Generating MSButton base on variable

Post by nodochau » Thu Feb 06, 2020 11:11 am

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

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Generating MSButton base on variable

Post by Grovkillen » Thu Feb 06, 2020 1:38 pm

nodochau wrote:
Thu Feb 06, 2020 11:11 am
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
A demo for you...

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*/
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Generating MSButton base on variable

Post by Grovkillen » Thu Feb 06, 2020 1:53 pm

@Dev:

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
*/
Will 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
*/
Let>ME=%Script%

Running: 15.0.24
version history

nodochau
Pro Scripter
Posts: 131
Joined: Wed Jan 16, 2019 12:59 pm

Re: Generating MSButton base on variable

Post by nodochau » Thu Feb 06, 2020 2:09 pm

Thanks Grovkillen,
I will try it today.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts