Dialog Designer Help

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Dialog Designer Help

Post by RNIB » Wed Oct 16, 2024 10:34 am

I am writing a macro that performs a series of tasks each of which consists of several stages. As individual stages are used in more than one tasks, I've set each stage as a sub routine and then used labels to define the start of each task e.g.

Label>Task1
GoSub>Stage1
GoSub>Stage2
GoSub>Stage 3

Label>Task2
GoSub>Stage2
GoSub>Stage 3

etc

I'm trying to design a custom dialogue that asks the user to select 1 of 4 tasks which then jumps to the respective labels but I'm getting very confused and don't really understand what I'm meant to be doing.

My custom dialogue has 4 checkboxes named:
Links
NoLinks
NonMass
Validate

There is also an OK and Cancel button

My code is:

Code: Select all


AddDialogHandler>Dialog1,Links,OnClick,chkBox
AddDialogHandler>Dialog1,NoLinks,OnClick,chkBox
AddDialogHandler>Dialog1,NonMass,OnClick,chkBox
AddDialogHandler>Dialog1,Validate,OnClick,chkBox

Dialog>Dialog1
object Dialog1: TForm
  Left = 255
  Top = 105
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Select Option'
  ClientHeight = 211
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 32
    Width = 293
    Height = 13
    Caption = 'Please Select What You Want To Do From the Options Below'
  end
  object NoLinks: TCheckBox
    Left = 24
    Top = 64
    Width = 393
    Height = 17
    Alignment = taLeftJustify
    Caption = 'Repair Mass Ingested Titles Missing Links In The NCC'
    TabOrder = 0
  end
  object Links: TCheckBox
    Left = 24
    Top = 80
    Width = 393
    Height = 17
    Alignment = taLeftJustify
    Caption = 'Repair Mass Ingested Titles That Have Links In The NCC'
    TabOrder = 1
  end
  object NonMass: TCheckBox
    Left = 24
    Top = 96
    Width = 393
    Height = 17
    Alignment = taLeftJustify
    Caption = 'Repair Non Mass Ingested Titles'
    TabOrder = 2
  end
  object Validate: TCheckBox
    Left = 24
    Top = 113
    Width = 393
    Height = 17
    Alignment = taLeftJustify
    Caption = 'Only Validate Rebuilt Titles'
    TabOrder = 3
  end
  object MSButton1: tMSButton
    Left = 24
    Top = 158
    Width = 75
    Height = 25
    Caption = 'OK'
    ModalResult = 1
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 132
    Top = 158
    Width = 75
    Height = 25
    Caption = 'Cancel'
    ModalResult = 2
    TabOrder = 5
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1


Show>Dialog1,modalResult
If>modalResult=1
Else
Exit>0
Endif

SRT>chkBox
GetDialogProperty>Dialog1,Links,Checked,LinkCheck
GetDialogProperty>Dialog1,NoLinks,Checked,NoLinkCheck
GetDialogProperty>Dialog1,NonMass,Checked,NonMassCheck
GetDialogProperty>Dialog1,Validate,Checked,ValidateCheck
END>chkBox

If>LinkCheck=True
GoTo>Links
Endif
If>NoLinkCheck=True
GoTo>NoLinks
Endif
If>NonMassCheck=True
GoTo>NonMass
Endif
If>ValidateCheck=True
GoTo>Validate
Endif
This isn't working and no matter what option I check, the same sub routines run.

Any ideas?

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

Re: Dialog Designer Help

Post by Grovkillen » Wed Oct 16, 2024 10:58 am

What do you want to accomplish? Should the user be able to have multiple options (checkboxes) or only one option (radio buttons)?

If you want to just get the checkboxes states you can just look at the "GetDialogProperty..." and get the checked value.
Let>ME=%Script%

Running: 15.0.27
version history

RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Dialog Designer Help

Post by RNIB » Wed Oct 16, 2024 11:06 am

I want the user to be able to only select one option and, ideally, for that to only be submitted when the press the OK button.

I thought I was using the GetDialogProperty to get the checked value but then it's not redirecting to the correct label as no matter what option is selected, the same sub routines run

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

Re: Dialog Designer Help

Post by Grovkillen » Wed Oct 16, 2024 11:47 am

You're not using an event handler for what you're trying to do. You just check the states after the (modal) dialog is closed:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 255
  Top = 105
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Select Option'
  ClientHeight = 211
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 32
    Width = 293
    Height = 13
    Caption = 'Please Select What You Want To Do From the Options Below'
  end
  object NoLinks: TCheckBox
    Left = 24
    Top = 64
    Width = 393
    Height = 17
    Alignment = taLeftJustify
    Caption = 'Repair Mass Ingested Titles Missing Links In The NCC'
    TabOrder = 0
  end
  object Links: TCheckBox
    Left = 24
    Top = 80
    Width = 393
    Height = 17
    Alignment = taLeftJustify
    Caption = 'Repair Mass Ingested Titles That Have Links In The NCC'
    TabOrder = 1
  end
  object NonMass: TCheckBox
    Left = 24
    Top = 96
    Width = 393
    Height = 17
    Alignment = taLeftJustify
    Caption = 'Repair Non Mass Ingested Titles'
    TabOrder = 2
  end
  object Validate: TCheckBox
    Left = 24
    Top = 113
    Width = 393
    Height = 17
    Alignment = taLeftJustify
    Caption = 'Only Validate Rebuilt Titles'
    TabOrder = 3
  end
  object MSButton1: tMSButton
    Left = 24
    Top = 158
    Width = 75
    Height = 25
    Caption = 'OK'
    ModalResult = 1
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 132
    Top = 158
    Width = 75
    Height = 25
    Caption = 'Cancel'
    ModalResult = 2
    TabOrder = 5
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1
Show>Dialog1,modalResult
If>modalResult=1
Else
Exit>0
Endif

GetDialogProperty>Dialog1,Links,Checked,LinkCheck
GetDialogProperty>Dialog1,NoLinks,Checked,NoLinkCheck
GetDialogProperty>Dialog1,NonMass,Checked,NonMassCheck
GetDialogProperty>Dialog1,Validate,Checked,ValidateCheck

**BREAKPOINT**
If>LinkCheck=True
GoTo>Links
Endif
If>NoLinkCheck=True
GoTo>NoLinks
Endif
If>NonMassCheck=True
GoTo>NonMass
Endif
If>ValidateCheck=True
GoTo>Validate
Endif
But since you only want one option to be possible (radio button behavior) you need to tweak it a bit or just make each selection a button.
Let>ME=%Script%

Running: 15.0.27
version history

RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Dialog Designer Help

Post by RNIB » Wed Oct 16, 2024 1:47 pm

Ahh, got it. I understand now. Thank you for this, I was getting myself all mixed up. As you say, just need to sort out preventing multiple selections now.

Thanks again.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Dialog Designer Help

Post by JRL » Wed Oct 16, 2024 3:28 pm

RNIB wrote:just need to sort out preventing multiple selections now.
That's what radio boxes are for.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 238
  Top = 95
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Select Option'
  ClientHeight = 213
  ClientWidth = 381
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 24
    Top = 158
    Width = 75
    Height = 25
    Caption = 'OK'
    ModalResult = 1
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 132
    Top = 158
    Width = 75
    Height = 25
    Caption = 'Cancel'
    ModalResult = 2
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSRadioGroup1: tMSRadioGroup
    Left = 20
    Top = 37
    Width = 333
    Height = 100
    Caption = 'Please Select What You Want To Do From the Options Below'
    ItemIndex = 0
    Items.Strings = (
      'Repair Mass Ingested Titles Missing Links In The NCC'
      'Repair Mass Ingested Titles That Have Links In The NCC'
      'Repair Non Mass Ingested Titles'
      'Only Validate Rebuilt Titles')
    TabOrder = 0
    Text =
      'Repair Mass Ingested Titles Missing Links In The NCC'#13#10'Repair Mas' +
      's Ingested Titles That Have Links In The NCC'#13#10'Repair Non Mass In' +
      'gested Titles'#13#10'Only Validate Rebuilt Titles'#13#10
  end
end
EndDialog>Dialog1
Show>Dialog1,modalResult
If>modalResult=1
Else
Exit>0
Endif
GetDialogProperty>Dialog1,MSRadioGroup1,ItemIndex,vSelected

**BREAKPOINT**
If>vSelected=0
GoTo>Links
Endif
If>vSelected=1
GoTo>NoLinks
Endif
If>vSelected=2
GoTo>NonMass
Endif
If>vSelected=3
GoTo>Validate
Endif

RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Dialog Designer Help

Post by RNIB » Wed Oct 16, 2024 3:40 pm

JRL wrote:
Wed Oct 16, 2024 3:28 pm
RNIB wrote:just need to sort out preventing multiple selections now.
That's what radio boxes are for.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 238
  Top = 95
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Select Option'
  ClientHeight = 213
  ClientWidth = 381
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 24
    Top = 158
    Width = 75
    Height = 25
    Caption = 'OK'
    ModalResult = 1
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 132
    Top = 158
    Width = 75
    Height = 25
    Caption = 'Cancel'
    ModalResult = 2
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSRadioGroup1: tMSRadioGroup
    Left = 20
    Top = 37
    Width = 333
    Height = 100
    Caption = 'Please Select What You Want To Do From the Options Below'
    ItemIndex = 0
    Items.Strings = (
      'Repair Mass Ingested Titles Missing Links In The NCC'
      'Repair Mass Ingested Titles That Have Links In The NCC'
      'Repair Non Mass Ingested Titles'
      'Only Validate Rebuilt Titles')
    TabOrder = 0
    Text =
      'Repair Mass Ingested Titles Missing Links In The NCC'#13#10'Repair Mas' +
      's Ingested Titles That Have Links In The NCC'#13#10'Repair Non Mass In' +
      'gested Titles'#13#10'Only Validate Rebuilt Titles'#13#10
  end
end
EndDialog>Dialog1
Show>Dialog1,modalResult
If>modalResult=1
Else
Exit>0
Endif
GetDialogProperty>Dialog1,MSRadioGroup1,ItemIndex,vSelected

**BREAKPOINT**
If>vSelected=0
GoTo>Links
Endif
If>vSelected=1
GoTo>NoLinks
Endif
If>vSelected=2
GoTo>NonMass
Endif
If>vSelected=3
GoTo>Validate
Endif
I did consider radio buttons and agree that it definitely looks better and is a much simpler approach. I elected to use checkboxes though because I didn't want to have any one option selected by default as what the macro does is kinda irreversible and I wanted to reduce the chances of someone inadvertently clicking OK before they had made sure they'd selected the correct option.

I got it working with checkboxes by linking the state of each checkbox to each other with GetDialogProperty and SetDialogProperty.

I'm probably being over cautious, it's just that this might end up being used on live data so I'm being a little paranoid.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Dialog Designer Help

Post by JRL » Wed Oct 16, 2024 3:59 pm

For future reference. Setting ItemIndex to -1 displays a radio group with nothing preselected. Once a selection is made, there is not a way to return to no selection unless you create a way to return to no selection. For example a button could be made to reset ItemIndex to -1.

RNIB
Macro Veteran
Posts: 195
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Dialog Designer Help

Post by RNIB » Wed Oct 16, 2024 4:02 pm

Ahh, okay. Well that is definitely better :lol: Didn't realise you could do that.

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