Checkboxes looping in Dialog

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Checkboxes looping in Dialog

Post by Jerry Thomas » Wed Feb 09, 2011 3:44 pm

I have 2 checkboxes that I want to be opposites.
My problem is my script gets into a loop because the action of the subroutine triggers the subroutine again.

I know there is a fix for this but can't come up with it.
Suggestions?

Code: Select all

AddDialogHandler>Timer,cbFixed,OnClick,Timing(Fixed)
AddDialogHandler>Timer,cbRandom,OnClick,Timing(Random)
...

SRT>Timing
  //Timing will be Fixed or Random
  Let>TimingOption=Timing_Var_1

  If>TimingOption=Fixed
    SetDialogProperty>Timer,cbFixed,Checked,True
    SetDialogProperty>Timer,cbRandom,Checked,False
  Else
    SetDialogProperty>Timer,cbRandom,Checked,True
    SetDialogProperty>Timer,cbFixed,Checked,False
  Endif
END>Timing
Here is a working script you can use

Code: Select all

Dialog>Timer
object Timer: TForm
  Left = 640
  Top = 243
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'MAKETest'
  ClientHeight = 472
  ClientWidth = 314
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'MS Sans Serif'
  Font.Style = [fsBold]
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 16
  object lblTiming: TLabel
    Left = 40
    Top = 88
    Width = 52
    Height = 16
    Caption = 'Timing:'
  end
  object cbFixed: TCheckBox
    Left = 110
    Top = 88
    Width = 60
    Height = 17
    Caption = 'Fixed'
    Checked = True
    State = cbChecked
    TabOrder = 0
  end
  object cbRandom: TCheckBox
    Left = 192
    Top = 88
    Width = 80
    Height = 17
    Caption = 'Random'
    TabOrder = 1
  end
end
EndDialog>Timer

AddDialogHandler>Timer,cbFixed,OnClick,Timing(Fixed)
AddDialogHandler>Timer,cbRandom,OnClick,Timing(Random)

Show>Timer,r

SRT>Timing
  //Timing will be Fixed or Random
  Let>TimingOption=Timing_Var_1
  If>TimingOption=Fixed
    SetDialogProperty>Timer,cbFixed,Checked,True
    SetDialogProperty>Timer,cbRandom,Checked,False
  Else
    SetDialogProperty>Timer,cbRandom,Checked,True
    SetDialogProperty>Timer,cbFixed,Checked,False
  Endif
END>Timing

Thanks,
Jerry

[email protected]

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Wed Feb 09, 2011 4:35 pm

I figured it out

If I use OnMouseUp, then the subroutine changing the Checked value is not 'caught' by the dialog handler.

Code: Select all

AddDialogHandler>Timer,cbFixed,OnMouseUp,Timing(Fixed)
Thanks,
Jerry

[email protected]

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Thu Feb 10, 2011 3:18 am

Jerry,
Would RadioGroup meet your requirement with less code?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Thu Feb 10, 2011 3:22 am

I find Jerry's code intriguing.
Referring to his AddDialogHandler>Timer,cbFixed,OnMouseUp,Timing(Fixed),
I'm not sure if MS support arguments (eg Fixed) in a calling subroutine.
By default, in any case, all parameters are visible globally.

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

Post by Marcus Tettmar » Thu Feb 10, 2011 9:27 am

armsys wrote:I find Jerry's code intriguing.
Referring to his AddDialogHandler>Timer,cbFixed,OnMouseUp,Timing(Fixed),
I'm not sure if MS support arguments (eg Fixed) in a calling subroutine.
By default, in any case, all parameters are visible globally.
From the help file topic "AddDialogHandler":

You can specify values to pass into the subroutine by including them within parentheses after the subroutine name. These are then set to Subroutine_Var_1, Subroutine_Var_2 etc, in the same way as parameters passed via GoSub. See examples.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Thu Feb 10, 2011 9:44 am

Marcus,
Thanks. Yes, it's in the manual. In fact, the arguments passing applies to both GoSub and AddDialogHandler. So my understanding in my last post was wrong.

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