Ask Dialog with Position Control

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

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

Ask Dialog with Position Control

Post by JRL » Thu Jul 31, 2014 2:52 pm

This script was inspired by this thread. The script is useful if you want to simulate using an Ask> dialog that you can display at a specific position on the screen. If that functionality is unneeded, it's much easier to simply use the built in Macro Scheduler Ask> function.

The script could be used as an included script or you could just copy and paste it directly into your script. Somewhere toward the bottom of your script would be good place to put it so it's out of the way. It's unlikely you'll need to make any changes to it if you're using it for the intended purpose. Note the first few lines can be unremarked to provide a sample usage.

If you're interested, I've put more technical reading at the bottom of the post.

Questions or comments?

Hope this is useful,
Dick

Code: Select all

//Unremark the following two lines for example usage:
//GoSub>AskDialog,Is Macro Scheduler the most useful software you've ever worked with?,ResultVariable,300,20

//MDL>ResultVariable





//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]

SRT>AskDialog
Let>AskDialogDoneFlag=0
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog
EndIf

AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo

Let>BuildAskDialogFlag=0

Show>AskDialog
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
EndIf


SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255

Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop

SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes

SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo

Label>AskDialogEnd
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog
1) The dialog includes a png file that displays a question mark. I stole the image directly from a screen capture of the original Macro Scheduler Ask> dialog. Used msPaint, to crop the image down to a 33x33 pixel size and then used paint to modify the small question mark balloon image giving it an orange colored background. I used IrFanView to open the png file and resave it making the orange color the transparent color for the image. The purpose for this is so that no matter what color the dialog background is, only the question mark balloon will be seen, the image's rectangular background will be transparent. The image was imported into the dialog using Macro Scheduler's Dialog Designer. I placed, positioned and sized an image object, then typed the path and name of the question mark png file into the "LoadImage" property field.

2) If you study the script you may notice that the GoSub>AskDialog's second parameter is a scripter assignable result variable. There is a trick to get the subroutine to return a value to a scripter's variable assignment. The trick is more fully explained HERE. But the bottom line is that we assign the result of the dialog selection to the "value" of the "AskDialog_var_2" variable by putting percents around the "AskDialog_var_2" variable.
The line looks like: Let>%AskDialog_var_2%=YES and Let>%AskDialog_var_2%=NO. Since the value of "AskDialog_var_2" as assigned by the GoSub>AskDialog subroutine call is "ResultVariable" (in the sample GoSub line), The new value of "ResultVariable" becomes either "YES" or "NO".

[email protected]
Junior Coder
Posts: 25
Joined: Wed Jul 20, 2011 3:07 pm

Re: Ask Dialog with Position Control

Post by [email protected] » Mon Aug 04, 2014 2:24 am

JRL,
I had to make a couple of modifications to your script to take care of multiple lines in the Ask message.
In your original script if the message is more than 2 lines, the buttons are on top of the message.
In the attached modified script, I calculate the height of the dialog box with the multi-line message and set the buttons just above the bottom of the box.

[email protected]
Junior Coder
Posts: 25
Joined: Wed Jul 20, 2011 3:07 pm

Re: Ask Dialog with Position Control

Post by [email protected] » Mon Aug 04, 2014 2:26 am

I forgot to mention that I get multiple lines with the insertion of %CRLF% for long messages.

[email protected]
Junior Coder
Posts: 25
Joined: Wed Jul 20, 2011 3:07 pm

Re: Ask Dialog with Position Control

Post by [email protected] » Mon Aug 04, 2014 2:46 pm

JRL
I made additional changes. It was not handling larger number of lines well.
Also it was not resetting for subsequent ASK dialogs.
I believe it is working under all conditions now.

Code: Select all

//Unremark the following two lines for example usage:

//Let>Line1=Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line2=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?
//Let>Line3=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line4=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?
//Let>Line5=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?
//Let>Line6=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?
//Let>Line7=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line8=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line9=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line10=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//
//GoSub>AskDialog,%Line1%,ResultVariable,300,20
//GoSub>AskDialog,%Line2%,ResultVariable,300,20
//GoSub>AskDialog,%Line3%,ResultVariable,300,20
//GoSub>AskDialog,%Line4%,ResultVariable,300,20
//GoSub>AskDialog,%Line5%,ResultVariable,300,20
//GoSub>AskDialog,%Line6%,ResultVariable,300,20
//GoSub>AskDialog,%Line7%,ResultVariable,300,20
//GoSub>AskDialog,%Line8%,ResultVariable,300,20
//GoSub>AskDialog,%Line9%,ResultVariable,300,20
//GoSub>AskDialog,%Line10%,ResultVariable,300,20
//MDL>ResultVariable

//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]
SRT>AskDialog
Let>AskDialogDoneFlag=0
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog
EndIf

AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo

Let>BuildAskDialogFlag=0

Show>AskDialog
SetDialogProperty>AskDialog,,AutoSize,True
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False
Length>AskDialog_var_1,MsgLen
Let>AskDialogHigh={20+((Int(%MsgLen%)*6)/%AskDiaWide%)*25}
If>AskDialogHigh<100
    Let>AskDialogHigh=100
Endif
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  Let>AskButton1Y={%AskDialogHigh%-30}
  Let>AskButton2Y={%AskDialogHigh%-30}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
  SetDialogProperty>AskDialog,MSButton1,Top,AskButton1Y
  SetDialogProperty>AskDialog,MSButton2,Top,AskButton2Y
EndIf

SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,ClientHeight,AskDialogHigh
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes
SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo
Label>AskDialogEnd
SetDialogProperty>AskDialog,,ClientWidth,150
SetDialogProperty>AskDialog,,ClientHeight,100
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog


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

Re: Ask Dialog with Position Control

Post by JRL » Mon Aug 04, 2014 3:56 pm

Mick,
Testing your last code, using 10 lines, the buttons covered the bottom of the text on my computer so I remarked your height calculation and put in a different one. How does this work for you using "line10" (which is already unremarked)



Code: Select all

//Unremark the following two lines for example usage:
//Let>Line1=Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line2=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?
//Let>Line3=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line4=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?
//Let>Line5=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?
//Let>Line6=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?
//Let>Line7=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line8=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//Let>Line9=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
Let>Line10=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%crlf%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%crlf%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%crlf%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%crlf%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?%crlf%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//
//GoSub>AskDialog,%Line1%,ResultVariable,300,20
//GoSub>AskDialog,%Line2%,ResultVariable,300,20
//GoSub>AskDialog,%Line3%,ResultVariable,300,20
//GoSub>AskDialog,%Line4%,ResultVariable,300,20
//GoSub>AskDialog,%Line5%,ResultVariable,300,20
//GoSub>AskDialog,%Line6%,ResultVariable,300,20
//GoSub>AskDialog,%Line7%,ResultVariable,300,20
//GoSub>AskDialog,%Line8%,ResultVariable,300,20
//GoSub>AskDialog,%Line9%,ResultVariable,300,20
GoSub>AskDialog,%Line10%,ResultVariable,300,20
//MDL>ResultVariable

//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]
SRT>AskDialog
Let>AskDialogDoneFlag=0
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog
EndIf
AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo
Let>BuildAskDialogFlag=0
Show>AskDialog
SetDialogProperty>AskDialog,,AutoSize,True
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False


Separate>AskDialog_var_1,crlf,vAskDialogLine
Let>AskDialogHigh={(%vAskDialogLine_Count%*13)+60}

/*
Length>AskDialog_var_1,MsgLen
Let>AskDialogHigh={20+((Int(%MsgLen%)*6)/%AskDiaWide%)*25}
*/


If>AskDialogHigh<100
    Let>AskDialogHigh=100
Endif
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  Let>AskButton1Y={%AskDialogHigh%-30}
  Let>AskButton2Y={%AskDialogHigh%-30}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
  SetDialogProperty>AskDialog,MSButton1,Top,AskButton1Y
  SetDialogProperty>AskDialog,MSButton2,Top,AskButton2Y
EndIf
SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,ClientHeight,AskDialogHigh
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes
SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo
Label>AskDialogEnd
SetDialogProperty>AskDialog,,ClientWidth,150
SetDialogProperty>AskDialog,,ClientHeight,100
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog

[email protected]
Junior Coder
Posts: 25
Joined: Wed Jul 20, 2011 3:07 pm

Re: Ask Dialog with Position Control

Post by [email protected] » Mon Aug 04, 2014 4:41 pm

JRL,
Yes it works fine on my screen.
I had considered your approach but tried to do it without counting CRLFs incase someone just used CR or LF, but it is more accurate to do the count. So I just added this comment line under Usage:
//Separate multi-line messages with %CRLF% not just %CR% or %LF%

Thank you very much for your help.

Code: Select all

//Unremark the following five lines for example usage:
//Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
//GoSub>AskDialog,%Lines%,ResultVariable,300,20
//MDL>ResultVariable

//Edit - 01/19/2015
//SetDialogObjectFocus>AskDialog,MSButton1
//Let>ResultVariable={"ResultVariable"}

//The previous line is necessary to reset the text for repeat usage of the dialog.  The position of the the line in your code
//should be immediately after the result variable is used.  In the example it is right after the result is displayed.
//Thank you jpuziano for discovering there is an issue when the line is not included.

//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]
//Separate multi-line messages with %CRLF% not just %CR% or %LF%

SRT>AskDialog
Let>AskDialogDoneFlag=0
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog
EndIf
AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo
Let>BuildAskDialogFlag=0
Show>AskDialog
SetDialogProperty>AskDialog,,AutoSize,True
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False


Separate>AskDialog_var_1,crlf,vAskDialogLine
Let>AskDialogHigh={(%vAskDialogLine_Count%*13)+60}

/*
Length>AskDialog_var_1,MsgLen
Let>AskDialogHigh={20+((Int(%MsgLen%)*6)/%AskDiaWide%)*25}
*/


If>AskDialogHigh<100
    Let>AskDialogHigh=100
Endif
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  Let>AskButton1Y={%AskDialogHigh%-30}
  Let>AskButton2Y={%AskDialogHigh%-30}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
  SetDialogProperty>AskDialog,MSButton1,Top,AskButton1Y
  SetDialogProperty>AskDialog,MSButton2,Top,AskButton2Y
EndIf
SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,ClientHeight,AskDialogHigh
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes
SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo
Label>AskDialogEnd
SetDialogProperty>AskDialog,,ClientWidth,150
SetDialogProperty>AskDialog,,ClientHeight,100
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Ask Dialog with Position Control

Post by jpuziano » Mon Jan 19, 2015 8:02 pm

Hi JRL,

Thanks for posting the change to your code above:
JRL's example code above wrote://Edit - 01/19/2015//SetDialogObjectFocus>AskDialog,MSButton1
//Let>ResultVariable={"ResultVariable"}
//The previous line is necessary to reset the text for repeat usage of the dialog. The position of the the line in your code
//should be immediately after the result variable is used. In the example it is right after the result is displayed.
//Thank you jpuziano for discovering there is an issue when the line is not included.
But what happens if you don't make use of the result variable right away in the code? Code can branch off and there may be multiple places where you might want to use the result variable so potentially you might have to reset this in multiple places.

A simple solution might be to store the value of ResultVariable in another variable immediately after using the subroutine like this:

Code: Select all

GoSub>AskDialog,%Lines%,ResultVariable,300,20

//save the result in myResultVariable which can be used any time
Let>myResultVariable=ResultVariable

//reset ResultVariable for next usage of the AskDialog subroutine
Let>ResultVariable={"ResultVariable"}
But that seems clunky as it is extra lines of code you must remember to insert after the GoSub> line.

Below is a solution to this with a small one-line modification to the AskDialog subroutine so that you don't need those extra lines of code, just call the AskDialog subroutine and use the result at any time after that, nothing to reset.
out-take from full code below wrote://JP - line below allows repeat usage of AskDialog without having to reset anything AFTER we use the result
//however the 2nd parameter (variable name) we pass in to this subroutine must be: AskDialogResultVariable
Let>AskDialog_var_2={"AskDialogResultVariable"}
Note that ResultVariable is pretty generic for a variable name so for clarity I used AskDialogResultVariable instead.

JRL I also inserted your line to keep the AskDialog defaulting on the Yes button when it opens into the subroutine, see below:
another out-take from full code below wrote://JP - line below ensures when AskDialog opens, the Yes button will always have focus
//that way, it only takes a single tap of the Tab key to shift focus to the No button
SetDialogObjectFocus>AskDialog,MSButton1
Below I show JRL's example with the above modifications. Two calls to the Ask Dialog subroutine are included so you can run this as-is to see that whatever choices you choose, they will be registered correctly. Also the Yes button will always have focus when the Ask Dialog opens no matter what choice you made the first time around:

Code: Select all

//Unremark the following five lines for example usage:
Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
GoSub>AskDialog,%Lines%,AskDialogResultVariable,300,20
MDL>AskDialogResultVariable

Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
GoSub>AskDialog,%Lines%,AskDialogResultVariable,300,20
MDL>AskDialogResultVariable

//Edit - 01/19/2015
//SetDialogObjectFocus>AskDialog,MSButton1
//Let>ResultVariable={"ResultVariable"}
//The previous line is necessary to reset the text for repeat usage of the dialog.  The position of the the line in your code
//should be immediately after the result variable is used.  In the example it is right after the result is displayed.
//Thank you jpuziano for discovering there is an issue when the line is not included.
//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]
//Separate multi-line messages with %CRLF% not just %CR% or %LF%
SRT>AskDialog
Let>AskDialogDoneFlag=0
//JP - line below allows repeat usage of AskDialog without having to reset anything AFTER we use the result
//however the 2nd parameter (variable name) we pass in to this subroutine must be: AskDialogResultVariable
Let>AskDialog_var_2={"AskDialogResultVariable"}
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog
EndIf
AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo
Let>BuildAskDialogFlag=0

//JP - line below ensures when AskDialog opens, the Yes button will always have focus
//that way, it only takes a single tap of the Tab key to shift focus to the No button 
SetDialogObjectFocus>AskDialog,MSButton1

Show>AskDialog
SetDialogProperty>AskDialog,,AutoSize,True
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False
Separate>AskDialog_var_1,crlf,vAskDialogLine
Let>AskDialogHigh={(%vAskDialogLine_Count%*13)+60}

/*
Length>AskDialog_var_1,MsgLen
Let>AskDialogHigh={20+((Int(%MsgLen%)*6)/%AskDiaWide%)*25}
*/
If>AskDialogHigh<100
    Let>AskDialogHigh=100
Endif
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  Let>AskButton1Y={%AskDialogHigh%-30}
  Let>AskButton2Y={%AskDialogHigh%-30}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
  SetDialogProperty>AskDialog,MSButton1,Top,AskButton1Y
  SetDialogProperty>AskDialog,MSButton2,Top,AskButton2Y
EndIf
SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,ClientHeight,AskDialogHigh
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes
SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo
Label>AskDialogEnd
SetDialogProperty>AskDialog,,ClientWidth,150
SetDialogProperty>AskDialog,,ClientHeight,100
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog
Note that we do have a dependency when we write the GoSub line:

GoSub>AskDialog,%Lines%,AskDialogResultVariable,300,20

We MUST use the variable name AskDialogResultVariable or this isn't going to work for subsequent uses... so I might remind myself of this fact by including the following Usage comment lines at the top of the subroutine... and maybe even before each time I use the GoSub line like so...

//Usage:
//GoSub>AskDialog,Message Text,AskDialogResultVariable,[Xposition],[Yposition]
//2nd parameter (variable name) passed in MUST BE AskDialogResultVariable or subsequent uses will fail
//Separate multi-line messages with %CRLF% not just %CR% or %LF%
GoSub>AskDialog,%Lines%,AskDialogResultVariable,300,20

Now here's the challenge...

Who out there can modify JRL's excellent routine so that IT DOES NOT MATTER what variable name we pass in as the second parameter on the GoSub line... and not require us to reset anything after returning from the GoSub... just use the variable later whenever.

That would allow us to pass in a variable name that will make sense later in the code... instead of just AskDialogResultVariable... we might have:

do_we_need_a_search_screen=YES
add_tax=NO
do_obvious_variable_names_make_sense=YES

Thanks again for posting this very helpful routine JRL... and looking forward to see if anyone can answer the challenge above. :wink:
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Re: Ask Dialog with Position Control

Post by JRL » Tue Jan 20, 2015 2:56 am

Who out there can modify JRL's excellent routine so that IT DOES NOT MATTER what variable name we pass in as the second parameter on the GoSub line...
I'm likely the only other person on the planet who cares enough to make any attempt. :wink:
Does this work for you? Works for me.

Made the parameter in the subroutine call explicit text rather than resetting to explicit text. don't know why I didn't do this to begin with. (Perhaps you'll let me know why when you tell me that this doesn't work.)

Also remarked out the Let>AskDialog_var_2={"AskDialogResultVariable"} line

Also created a loop so you can run the dialog over and over until you press ctrl + esc or pick the stop button.

Code: Select all

Label>ReDo
Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
GoSub>AskDialog,%Lines%,{"XYZ"},300,20
MDL>XYZ
Goto>ReDo


//Edit - 01/19/2015
//SetDialogObjectFocus>AskDialog,MSButton1
//Let>ResultVariable={"ResultVariable"}
//The previous line is necessary to reset the text for repeat usage of the dialog.  The position of the the line in your code
//should be immediately after the result variable is used.  In the example it is right after the result is displayed.
//Thank you jpuziano for discovering there is an issue when the line is not included.
//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]
//Separate multi-line messages with %CRLF% not just %CR% or %LF%
SRT>AskDialog
Let>AskDialogDoneFlag=0
//JRL - removed the line below
//JP - line below allows repeat usage of AskDialog without having to reset anything AFTER we use the result
//however the 2nd parameter (variable name) we pass in to this subroutine must be: AskDialogResultVariable
//Let>AskDialog_var_2={"AskDialogResultVariable"}
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog
EndIf
AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo
Let>BuildAskDialogFlag=0

//JP - line below ensures when AskDialog opens, the Yes button will always have focus
//that way, it only takes a single tap of the Tab key to shift focus to the No button 
SetDialogObjectFocus>AskDialog,MSButton1

Show>AskDialog
SetDialogProperty>AskDialog,,AutoSize,True
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False
Separate>AskDialog_var_1,crlf,vAskDialogLine
Let>AskDialogHigh={(%vAskDialogLine_Count%*13)+60}

/*
Length>AskDialog_var_1,MsgLen
Let>AskDialogHigh={20+((Int(%MsgLen%)*6)/%AskDiaWide%)*25}
*/
If>AskDialogHigh<100
    Let>AskDialogHigh=100
Endif
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  Let>AskButton1Y={%AskDialogHigh%-30}
  Let>AskButton2Y={%AskDialogHigh%-30}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
  SetDialogProperty>AskDialog,MSButton1,Top,AskButton1Y
  SetDialogProperty>AskDialog,MSButton2,Top,AskButton2Y
EndIf
SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,ClientHeight,AskDialogHigh
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes
SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo
Label>AskDialogEnd
SetDialogProperty>AskDialog,,ClientWidth,150
SetDialogProperty>AskDialog,,ClientHeight,100
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Ask Dialog with Position Control

Post by jpuziano » Tue Jan 20, 2015 7:28 pm

JRL wrote:Made the parameter in the subroutine call explicit text rather than resetting to explicit text. don't know why I didn't do this to begin with. (Perhaps you'll let me know why when you tell me that this doesn't work.)
JRL that works great... now I can use a variety of result variables and use their values later at any time and not have to add extra code to "reset" them after use (or ever).
JRL wrote:Also remarked out the Let>AskDialog_var_2={"AskDialogResultVariable"} line
Yup, not needed anymore.
JRL wrote:Also created a loop so you can run the dialog over and over until you press ctrl + esc or pick the stop button.
Sure. Ctrl + Esc or the Stop button both work to stop it.

Sidenote: I found something weird when I right-clicked the Macro Scheduler systray icon (yellow robot head) though. The right-click systray menu appears and if you run from the MS main window, Stop will not be grayed out and it will work if you use the mouse to click it... however the keyboard shortcut shown next to Stop in the right-click systray menu is Ctrl+B and when I hit Ctrl+B it does nothing. I am running Macro Scheduler Pro 14.2.02 - do you see the same thing JRL?

Anyway, made a few more changes to this... First there was a bit of flashing of AskDialog appearing in different places on the screen. I solved this with your usual trick of making it invisible first... I added the lines below just ahead of Show>AskDialog:

Code: Select all

//Alphablend the dialog down to 0 so it is invisible
SetDialogProperty>AskDialog,,AlphaBlend,True
SetDialogProperty>AskDialog,,AlphaBlendValue,0
I see you already had the alphablend statement in there just before entering the Loop so I figure you just forgot to make it invisible first. This solves the flashing problem...

Code: Select all

SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
I also moved the lines below up as I think they only need to be run once... and it seems to work fine. Someone please let me know if this is not good form.

Code: Select all

EndDialog>AskDialog

//JP - moved these lines inside the If/EndIf as they only need to run once when dialog instantiated
AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo
Let>BuildAskDialogFlag=0

EndIf
//AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
//AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
//AddDialogHandler>AskDialog,,OnClose,AskDialogNo
//Let>BuildAskDialogFlag=0
And I changed the text in Lines slightly, to better show that lines break at each embedded %CRLF% and that %CRLF%%CRLF% is honored and will produce a blank line...

So here's the code:

Code: Select all

Label>ReDo
//Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've%CRLF%ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever%CRLF%worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked%CRLF%with?%CRLF%%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
GoSub>AskDialog,Lines,{"XYZ"},300,20
MDL>XYZ
Goto>ReDo

//Edit - 01/19/2015
//SetDialogObjectFocus>AskDialog,MSButton1
//Let>ResultVariable={"ResultVariable"}
//The previous line is necessary to reset the text for repeat usage of the dialog.  The position of the the line in your code
//should be immediately after the result variable is used.  In the example it is right after the result is displayed.
//Thank you jpuziano for discovering there is an issue when the line is not included.
//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]
//Separate multi-line messages with %CRLF% not just %CR% or %LF%
SRT>AskDialog
Let>AskDialogDoneFlag=0
//JRL - removed the line below
//JP - line below allows repeat usage of AskDialog without having to reset anything AFTER we use the result
//however the 2nd parameter (variable name) we pass in to this subroutine must be: AskDialogResultVariable
//Let>AskDialog_var_2={"AskDialogResultVariable"}
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog

//JP - moved these lines inside the If/EndIf as they only need to run once when dialog instantiated
AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo
Let>BuildAskDialogFlag=0

EndIf
//AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
//AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
//AddDialogHandler>AskDialog,,OnClose,AskDialogNo
//Let>BuildAskDialogFlag=0

//JP - line below ensures when AskDialog opens, the Yes button will always have focus
//that way, it only takes a single tap of the Tab key to shift focus to the No button 
SetDialogObjectFocus>AskDialog,MSButton1

//Alphablend the dialog down to 0 so it is invisible
SetDialogProperty>AskDialog,,AlphaBlend,True
SetDialogProperty>AskDialog,,AlphaBlendValue,0

Show>AskDialog

SetDialogProperty>AskDialog,,AutoSize,True
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False
Separate>AskDialog_var_1,crlf,vAskDialogLine
Let>AskDialogHigh={(%vAskDialogLine_Count%*13)+60}

/*
Length>AskDialog_var_1,MsgLen
Let>AskDialogHigh={20+((Int(%MsgLen%)*6)/%AskDiaWide%)*25}
*/
If>AskDialogHigh<100
    Let>AskDialogHigh=100
Endif
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  Let>AskButton1Y={%AskDialogHigh%-30}
  Let>AskButton2Y={%AskDialogHigh%-30}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
  SetDialogProperty>AskDialog,MSButton1,Top,AskButton1Y
  SetDialogProperty>AskDialog,MSButton2,Top,AskButton2Y
EndIf
SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,ClientHeight,AskDialogHigh
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes
SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo
Label>AskDialogEnd
SetDialogProperty>AskDialog,,ClientWidth,150
SetDialogProperty>AskDialog,,ClientHeight,100
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog
Only ONE problem remains...

The first time this runs, the positioning of the text within the AskDialog is very nice, good spacing on all sides. However on the next use, the positioning of the text is worse... spacing not so well calculated.

I tried a few things but at the moment can't see why this is happening. Can you JRL?
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Re: Ask Dialog with Position Control

Post by JRL » Tue Jan 20, 2015 9:07 pm

Only ONE problem remains...
Probably caused by autosize. Just moved the two objects back to their original positions after turning off autosize

Code: Select all

Label>ReDo
//Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've%CRLF%ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever%CRLF%worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked%CRLF%with?%CRLF%%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
GoSub>AskDialog,Lines,{"XYZ"},300,20
MDL>XYZ
Goto>ReDo
//Edit - 01/19/2015
//SetDialogObjectFocus>AskDialog,MSButton1
//Let>ResultVariable={"ResultVariable"}
//The previous line is necessary to reset the text for repeat usage of the dialog.  The position of the the line in your code
//should be immediately after the result variable is used.  In the example it is right after the result is displayed.
//Thank you jpuziano for discovering there is an issue when the line is not included.
//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]
//Separate multi-line messages with %CRLF% not just %CR% or %LF%
SRT>AskDialog
Let>AskDialogDoneFlag=0
//JRL - removed the line below
//JP - line below allows repeat usage of AskDialog without having to reset anything AFTER we use the result
//however the 2nd parameter (variable name) we pass in to this subroutine must be: AskDialogResultVariable
//Let>AskDialog_var_2={"AskDialogResultVariable"}
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog
//JP - moved these lines inside the If/EndIf as they only need to run once when dialog instantiated
AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo
Let>BuildAskDialogFlag=0
EndIf
//AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
//AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
//AddDialogHandler>AskDialog,,OnClose,AskDialogNo
//Let>BuildAskDialogFlag=0
//JP - line below ensures when AskDialog opens, the Yes button will always have focus
//that way, it only takes a single tap of the Tab key to shift focus to the No button 
SetDialogObjectFocus>AskDialog,MSButton1
//Alphablend the dialog down to 0 so it is invisible
SetDialogProperty>AskDialog,,AlphaBlend,True
SetDialogProperty>AskDialog,,AlphaBlendValue,0
Show>AskDialog
SetDialogProperty>AskDialog,,AutoSize,True
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False

//JRL - added the next four lines to return the label and image to their
//original positions after being shifted by the dialog autosize.
SetDialogProperty>AskDialog,Label1,Left,54
SetDialogProperty>AskDialog,Label1,Top,13
SetDialogProperty>AskDialog,MSImage1,Left,11
SetDialogProperty>AskDialog,MSImage1,Top,12

Separate>AskDialog_var_1,crlf,vAskDialogLine
Let>AskDialogHigh={(%vAskDialogLine_Count%*13)+60}
/*
Length>AskDialog_var_1,MsgLen
Let>AskDialogHigh={20+((Int(%MsgLen%)*6)/%AskDiaWide%)*25}
*/
If>AskDialogHigh<100
    Let>AskDialogHigh=100
Endif
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  Let>AskButton1Y={%AskDialogHigh%-30}
  Let>AskButton2Y={%AskDialogHigh%-30}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
  SetDialogProperty>AskDialog,MSButton1,Top,AskButton1Y
  SetDialogProperty>AskDialog,MSButton2,Top,AskButton2Y
EndIf
SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,ClientHeight,AskDialogHigh
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes
SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo
Label>AskDialogEnd
SetDialogProperty>AskDialog,,ClientWidth,150
SetDialogProperty>AskDialog,,ClientHeight,100
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog

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

Re: Ask Dialog with Position Control

Post by JRL » Thu Jan 22, 2015 5:34 pm

Had a better idea to prevent the objects from shifting up and left when autosize in used. Simply place an invisible object at the 0,0 position of the dialog. This prevents the dialog from shrinking down to meet the visible objects thus they don't lose their original positions.

In this case I added label0 to the dialog.
object Label0: TLabel
Left = 0
Top = 0
end

Code: Select all

Label>ReDo
//Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
Let>Lines=Is Macro Scheduler the most useful%CRLF%software you've ever worked with?%CRLF%Is Macro Scheduler the most useful software%CRLF%you've ever worked with?%CRLF%Is Macro Scheduler the most useful software you've%CRLF%ever worked with?%CRLF%Is Macro Scheduler the most useful software you've ever%CRLF%worked with?%CRLF%Is Macro Scheduler the most useful software you've ever worked%CRLF%with?%CRLF%%CRLF%Is Macro Scheduler the most useful software you've ever worked with?
GoSub>AskDialog,Lines,{"XYZ"},300,20
MDL>XYZ
Goto>ReDo
//Edit - 01/19/2015
//SetDialogObjectFocus>AskDialog,MSButton1
//Let>ResultVariable={"ResultVariable"}
//The previous line is necessary to reset the text for repeat usage of the dialog.  The position of the the line in your code
//should be immediately after the result variable is used.  In the example it is right after the result is displayed.
//Thank you jpuziano for discovering there is an issue when the line is not included.
//Usage:
//GoSub>AskDialog,Message Text,Result Variable,[Xposition],[Yposition]
//Separate multi-line messages with %CRLF% not just %CR% or %LF%
SRT>AskDialog
Let>AskDialogDoneFlag=0
//JRL - removed the line below
//JP - line below allows repeat usage of AskDialog without having to reset anything AFTER we use the result
//however the 2nd parameter (variable name) we pass in to this subroutine must be: AskDialogResultVariable
//Let>AskDialog_var_2={"AskDialogResultVariable"}
If>BuildAskDialogFlag={"BuildAskDialogFlag"}
Dialog>AskDialog
object AskDialog: TForm
  Alphablend = True
  AlphaBlendValue = 0
  AutoSize = True
  BorderIcons = []
  Caption = 'Confirm'
  ClientHeight = 100
  ClientWidth = 150
  Position = poScreenCenter
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 150
    Height = 100
    Caption = ''
    BevelOuter = bvNone
  end
  object Label0: TLabel
    Left = 0
    Top = 0
  end
  object Label1: TLabel
    Left = 54
    Top = 13
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 9
    Top = 60
    Width = 62
    Height = 24
    Caption = '&Yes'
    TabOrder = 1
    Default = True
  end
  object MSButton2: tMSButton
    Left = 77
    Top = 60
    Width = 62
    Height = 24
    Caption = '&No'
    TabOrder = 2
  end
  object MSImage1: tMSImage
    Left = 11
    Top = 12
    Width = 33
    Height = 33
    Transparent = True
        Picture.Data = {
      0954506E67496D61676589504E470D0A1A0A0000000D49484452000000210000
      00210802000000D88655380000000674524E5300FF00800040332B9A0D000007
      0E4944415478DAB5967B7014F51DC07FB7BBB77BBB7B7BBBB7F7CAC346124690
      201DB1C4B4995251A833B6D387ADD5F287603345696D6899C0940E1481A95A05
      4B29445B105A1CAD32210892D4E018B10FAB36A9A902C9B4C184BBE4C25D728F
      ECDDEEDDBEB7BFBD4784696AC096EFDDECFCE6EEFBFD7D7EDFE76F1DD6B665E0
      1A8BE34A1823CD2F92388AA11F599916907590CA489A9868E8DCF03F31922DC7
      9CA803C59C18E67420087094AD2CCBD00DD3D055DDCCCADA646C7CC98996AB66
      247FD00177B63F054110C77FEA4080A61B9AAE6B9A2E88F2E8D8E8EDAFB55E29
      23D5D2E1C45D048143826386CD2F13CDB0244557154D5195C191B13B4FAD9B9D
      11FF5E3BE5662892401DC00200861EFAA099A07F70A2FBAD8820A92EA7794335
      B5B4A16EEE755CF100504D520CE88AA628E18B89DB3A1FFA38C6F8DA768AA63D
      6E121AEBA6FDC510206495F58FBFF2FCF1C1FA85373850E4DCDBEF012DCE063C
      EB1FFE46EB9A65A6094814381190918D9490D734657038FAD5D33F9C99115973
      84A61996215104E4356058768E5114B43EFAF2337BBAFD0BEBBB0F3E50E1A3EE
      7EE8406FDF30C09C40161EFFD9EA96FB1B2519500470A32091B3318A925F74F8
      DE191843AB0E536ED6C7314E0CB10126285691ACE837ADF869426480A6FDE8C1
      CFEFDEB87CFBD36F6C7BEC0408CE03890B3737D41DDBBF8622314D076E0AB831
      309654C5AC184B0B2B5E69BE8CF1FEB70EC01CB02CC7B284AC143CB08069FF0F
      72925ABB74AB8155004D696AACE97C76E5D1AE330F6E7C0ED0738018AF9B1B78
      A9ADB9A69296556039004703D5B06271F1C3F0583211FFEE07DB2F61DC779076
      73BC9F4551542B685B96FD850C58578FECE979BD2F5D555DD3B400D9B276C96F
      5EEC6DDDF21260EB8098B8B1BEF285BDAB833CA168C0320182018606F149E542
      3892CBCBF7FE695D89716AC56E1822AF37C0F11E9840C3B019A05051B68603C8
      B21189E7612987788C6590D61D1D870FBD435C3FDF52957BBE34EFC94D5FCCC9
      A533410B920239519B4CA463B18BB1E1B3EBA2CFDA8CEE3B76310CE30F8460A8
      20C3AED74232E0B98A0EC10687830422212F1A17EFFE4E5B3CEDBC75E9EDB595
      C8C32BE705781226A3285007C380A2AAC9C9547A2A151D195837D256F0E38E5D
      04E50ED80C0E2AD9C72F44A978AEA237C5B58B00CF1FFBC7E6ADC7172F5FBEEA
      9B0D4D0B5196716A1A285A14D560B854594D2413B22846CE9F69B9B0CF66742E
      DB49926E7F30E4E1BCA534146C8AFB4E2F0A8133EF5AF55C5230766EF9F26D0D
      21CB72400F2E05C005741A329289445E9A1AFAA07753F27736E348E3131CEBE6
      FD2196E78B056B16372D961628C51A06213C9E858CE6FB966C6969CC8885FA2E
      3B0ACA0782F1CCE7F2423A31313179F62F5DBB5D6FD88C43B73CEA63488F37C0
      0782388E978E5F7E4EFB8442C658B6E591CEEFAFFAEC5796D78AB9C2EF66D909
      50AA43389285A9B428A446A3D1C137DB0F549CB319ED9F7B4C560D96F3FB4215
      1E0F379D83A2A559EE15E8A0030599AC4191281C049A5170029422552C10A824
      E795746A529C4A0C9C1D480EF61CAA192EF5C7BE055B7DACDBC3077D8190CBE5
      32AC72A0CA1509230003FDD6BBE7FF35345655E96B6AAA2770D434CA9D54F6D8
      308CCC542A934EA604A1F7CD577FEFFFE3473DD8B6602B86586E8F17F6A1D71F
      74E2443108A57C5AF670EA3AF5FEF6CD4F015D052676D7B7BFBEF9C7F7C08A9A
      CE077C18A699B501294914864727075E7DBABB51BA6C5EEDA8DA10E048DAE365
      79D88C419CC0CD728DD9E31D05EB37EEEF7BFB0C7057835C9AE488DF1ED8140A
      50BA566A581D5E88423A934E48E25432A3BC7B72FFA94F476798BBDBAB36F08C
      8BF6F01EAF8FE17882A41187A3586370FAEEF87947CFC977D8BA456E9A42CCF4
      9E9DAB690AB77BD6824DA74859013A91B31DC99DFBDB69EB62FFF1CF483330F6
      D6AC8D29B4CF43523443D22CC5B024EDC670178220701887A3C2DE7D5D6C45ED
      B22F2C7661C2CD378514D5D454359F93725256CE6560D3A5B2EA3FFBFFAC84FF
      DA75ABFC5FEFA85F05579ECFBA7D3CE7A169A78BC25D348613303D3849C15AD0
      4DF8E2006F61FB0296B239312B40809A9734359F15A5784A08FFFD3567367CB2
      41BE74CF19EEDAC373EEEF1BCEA27C2D47C30B1D85056B62048AE1F07277C1F0
      312CCD7A0D431792093193821EE89A9E92D4F1A1FEEC485FC08DBE70E3E4ECF7
      79519E70DD39309AB5E82017A8841BA30E042A3B719CF1F25E7F255CA7931393
      13F18BD148261913067B3837F1F22DD28C5BCDF27EF56BFFD72263B129C5A1A8
      3A4673FEEB17111EBFBFB206C789F878A4FFF52362E4BDEAAAAA8373463F6693
      2B7A4F9C96A742CD1253E7F656302C3F1A090F9CD87574417456ABAB6340F9C9
      A7B6310CE70D560E87C747BA7F79747EF8FFCFE858DCDA3382D6D5CD1D4FE586
      FFF08BE3F5A3B39A5C3503CA3373D69CCD5D47D0FC875D4F9EB8460C286DD50F
      F48EEAD2D0E9F6F9D7201F9F40FE0D1DA3C4EE67F099AE0000000049454E44AE
      426082}
  end
end
EndDialog>AskDialog
//JP - moved these lines inside the If/EndIf as they only need to run once when dialog instantiated
AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
AddDialogHandler>AskDialog,,OnClose,AskDialogNo
Let>BuildAskDialogFlag=0
EndIf
//AddDialogHandler>AskDialog,MSButton1,OnClick,AskDialogYes
//AddDialogHandler>AskDialog,MSButton2,OnClick,AskDialogNo
//AddDialogHandler>AskDialog,,OnClose,AskDialogNo
//Let>BuildAskDialogFlag=0
//JP - line below ensures when AskDialog opens, the Yes button will always have focus
//that way, it only takes a single tap of the Tab key to shift focus to the No button 
SetDialogObjectFocus>AskDialog,MSButton1
//Alphablend the dialog down to 0 so it is invisible
SetDialogProperty>AskDialog,,AlphaBlend,True
SetDialogProperty>AskDialog,,AlphaBlendValue,0
Show>AskDialog
SetDialogProperty>AskDialog,,AutoSize,True
SetDialogProperty>AskDialog,Label1,Caption,AskDialog_var_1
GetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,AutoSize,False

//JRL - Don't need these lines.  Added an object at the 0,0 position in the
//dialog instead.  Prevents autoSize from shifting other objects up and left.
//JRL - added the next four lines to return the label and image to their
//original positions after being shifted by the dialog autosize.
//SetDialogProperty>AskDialog,Label1,Left,54
//SetDialogProperty>AskDialog,Label1,Top,13
//SetDialogProperty>AskDialog,MSImage1,Left,11
//SetDialogProperty>AskDialog,MSImage1,Top,12

Separate>AskDialog_var_1,crlf,vAskDialogLine
Let>AskDialogHigh={(%vAskDialogLine_Count%*13)+60}
/*
Length>AskDialog_var_1,MsgLen
Let>AskDialogHigh={20+((Int(%MsgLen%)*6)/%AskDiaWide%)*25}
*/
If>AskDialogHigh<100
    Let>AskDialogHigh=100
Endif
Add>AskDiaWide,20
If>AskDiaWide<170
  Let>AskDiaWide=170
Else
  Let>AskButton1X={round(9+((%AskDiaWide%-150)/2))}
  Let>AskButton2X={round(77+((%AskDiaWide%-150)/2))}
  Let>AskButton1Y={%AskDialogHigh%-30}
  Let>AskButton2Y={%AskDialogHigh%-30}
  SetDialogProperty>AskDialog,MSButton1,Left,AskButton1X
  SetDialogProperty>AskDialog,MSButton2,Left,AskButton2X
  SetDialogProperty>AskDialog,MSButton1,Top,AskButton1Y
  SetDialogProperty>AskDialog,MSButton2,Top,AskButton2Y
EndIf
SetDialogProperty>AskDialog,Panel1,Visible,False
SetDialogProperty>AskDialog,,ClientWidth,AskDiaWide
SetDialogProperty>AskDialog,,ClientHeight,AskDialogHigh
SetDialogProperty>AskDialog,,Position,poScreenCenter
SetDialogProperty>AskDialog,,Left,AskDialog_var_3
SetDialogProperty>AskDialog,,Top,AskDialog_var_4
SetDialogProperty>AskDialog,,AlphaBlendValue,255
Label>Loop
  If>AskDialogDoneFlag=1
    Goto>AskDialogEnd
  EndIf
Goto>Loop
SRT>AskDialogYes
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=YES
  Let>AskDialogDoneFlag=1
END>AskDialogYes
SRT>AskDialogNo
  CloseDialog>AskDialog
  Let>%AskDialog_var_2%=NO
  Let>AskDialogDoneFlag=1
END>AskDialogNo
Label>AskDialogEnd
SetDialogProperty>AskDialog,,ClientWidth,150
SetDialogProperty>AskDialog,,ClientHeight,100
Let>AskDialogDoneFlag=0
Let>AskDialog_var_1=
Let>AskDialog_var_2=
Let>AskDialog_var_3=
Let>AskDialog_var_4=
END>AskDialog

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Ask Dialog with Position Control

Post by jpuziano » Thu Jan 22, 2015 6:51 pm

Yes, that works fine, seems stable and is less lines of code so thanks JRL!
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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