The Unofficial Macro Scheduler Puzzler of the Week 4

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

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

The Unofficial Macro Scheduler Puzzler of the Week 4

Post by JRL » Fri Oct 04, 2013 10:49 pm

As I mentioned in a post on Thursday, I run most of my scheduled scripts from one master script... well, actually from two master scripts. I have one called Tuesday Thru Saturday and One called Sunday - Monday. Each script is a series of Macro> functions with short waits between them. For example, Tuesday Thru Saturday starts out:

Code: Select all

Macro>%Script_Dir%\Daily labor.scp

Wait>5
Macro>%Script_Dir%\Sales Trend.scp

Wait>5
Macro>%Script_Dir%\Sales Data.scp

This has been very clean and very reliable for a long time. However, I've experienced some issues after recent software updates (not Macro Scheduler updates) where scripts will intermittently stop before they complete. The scripts all send me emails when they complete so I can discern which script failed but I don't know what within the failed script caused it to fail. When I run the scripts during the day they never fail. Very puzzling.

So I need to figure out a way to have the scripts report what they are doing as they are doing it. I could just use the built in logging but I've heard so many times on the forum that a solution for someone's problem wouldn't work because it involved writing info to a file, I've decided the solution to this problem can't involve writing any info to a file. I could insert messages into the scripts but I've experienced times where sending a message using the built in message> function has stolen focus from a window and caused issues, so I can't use any Macro Scheduler or VBScipt message functions.

I've decided the only way to make this work is to add a dialog to the master script and have the subordinate scripts update the dialog as they progress.

The goal for this week's puzzler is for you to come up with a master script that can do this. The master script's dialog needs to display whatever information a subordinate script sends to it, on a label. No information can be saved to a file nor can we use the clipboard. The master script should be able to fire off an unlimited number of scripts and the scripts should process sequentially. One script does not start until the previous script has ended. For puzzler contest continuity (and to make it easier for me to check the results), the master script should run the following script using three different names. The three script names should be puzzler1.scp, puzzler2.scp and puzzler3.scp. The only part of this code you will need to modify is wherever it says, "Send this message to a dialog"

To encapsulate.

- Put the following code in each of three different scripts modifying the send message lines.

- Write a master script that fires the three scripts sequentially and one at a time.

- The master script will display a dialog and in the dialog a label will display messages from the three scripts.

- Can't write anything to a file.

- Can't use the clipboard.

- Can't use any messages other than the master script's dialog.

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
If>kk>4
  Wait>1
  //Send this message to a dialog     %script_file% Complete
  Exit>0
EndIf
Wait>1
Goto>Loop
Entries will be judged on functionality, meeting the specified criteria, and neatness. Fewest lines may be used to break a tie or might not if the longer script is perceived by me to be better. Winning entry will receive 40 rep points and bragging rights.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sat Oct 05, 2013 2:15 pm

- Can't write anything to a file.

- Can't use the clipboard.
Is the registry an option?

Why not use Include instead of Macro ?

I would do the following if Include is an option.

Master Script:

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  Width = 350
  Height = 434
  HelpContext = 5000
  AutoScroll = True
  Caption = 'Puzzler Log'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 0
    Top = 0
    Width = 289
    Height = 396
    Align = alClient
    Caption = 'Label1'
    ExplicitWidth = 32
    ExplicitHeight = 13
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,ExitScript
Show>Dialog1

GetDate>varDate
GetTime>varTime
Let>varLog=%varDate% %varTime%: Executing Puzzler 1
SetDialogProperty>Dialog1,Label1,Caption,%varLog%
Include>%SCRIPT_DIR%\Puzzler 1.scp
SetDialogProperty>Dialog1,Label1,Caption,%varLog%
Wait>5

GetDate>varDate
GetTime>varTime
Let>varLog=%varLog%%CRLF%%varDate% %varTime%: Executing Puzzler 2
SetDialogProperty>Dialog1,Label1,Caption,%varLog%
Include>%SCRIPT_DIR%\Puzzler 2.scp
SetDialogProperty>Dialog1,Label1,Caption,%varLog%
Wait>5

GetDate>varDate
GetTime>varTime
Let>varLog=%varLog%%CRLF%%varDate% %varTime%: Executing Puzzler 3
SetDialogProperty>Dialog1,Label1,Caption,%varLog%
Include>%SCRIPT_DIR%\Puzzler 3.scp
SetDialogProperty>Dialog1,Label1,Caption,%varLog%%CRLF%Done!

Label>EndOfScriptLoop
  Wait>1
Goto>EndOfScriptLoop

SRT>ExitScript
  Exit>0
END>ExitScript
Save as "Puzzler 1"

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop1
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
GetDate>varDate
GetTime>varTime
Let>varLog=%varLog%%CRLF%%varDate% %varTime%: Ping number %kk%
SetDialogProperty>Dialog1,Label1,Caption,%varLog%
If>kk>4
  Wait>1
  GetDate>varDate
  GetTime>varTime
  Let>varLog=%varLog%%CRLF%%varDate% %varTime%:  %script_file% Complete
  Goto>EndOfPuzzler1Script
EndIf
Wait>1
Goto>Loop1

Label>EndOfPuzzler1Script


Save as "Puzzler 2"

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop2
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
GetDate>varDate
GetTime>varTime
Let>varLog=%varLog%%CRLF%%varDate% %varTime%: Ping number %kk%
SetDialogProperty>Dialog1,Label1,Caption,%varLog%
If>kk>4
  Wait>1
  GetDate>varDate
  GetTime>varTime
  Let>varLog=%varLog%%CRLF%%varDate% %varTime%:  %script_file% Complete
  Goto>EndOfPuzzler2Script
EndIf
Wait>1
Goto>Loop2

Label>EndOfPuzzler2Script


Save as "Puzzler 3"

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop3
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
GetDate>varDate
GetTime>varTime
Let>varLog=%varLog%%CRLF%%varDate% %varTime%: Ping number %kk%
SetDialogProperty>Dialog1,Label1,Caption,%varLog%
If>kk>4
  Wait>1
  GetDate>varDate
  GetTime>varTime
  Let>varLog=%varLog%%CRLF%%varDate% %varTime%:  %script_file% Complete
  Goto>EndOfPuzzler3Script
EndIf
Wait>1
Goto>Loop3

Label>EndOfPuzzler3Script

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

Post by JRL » Sun Oct 06, 2013 2:06 am

Rain wrote:Is the registry an option?
Its a file, so no.

Rain wrote:Why not use Include instead of Macro ?
The sample using macro> is just a sample of what I'm doing now. I was careful not to specifically mention any function when I said "fires" the scripts so include> is a valid method to use in the puzzler solution.

That said. I think there are better methods than include>. Include> has several problems. I have a dozen scripts in my master script. I would have to make sure I did not reuse any variables, subroutine names, label names, etc.

Unless someone else comes up with a "better" way by Friday next, you will be the winner. Your script is good and I greatly appreciate you taking the time to ponder the puzzler and submit an answer.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Oct 06, 2013 1:53 pm

JRL wrote:That said. I think there are better methods than include>. Include> has several problems. I have a dozen scripts in my master script. I would have to make sure I did not reuse any variables, subroutine names, label names, etc.
Makes sense.

Here are 2 solutions (With and without time stamp) using the Macro command. I'm using a memo box instead of a label to send the messages to a dialog.

Master Script

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 477
  Top = 104
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize, biMaximize]
  Caption = 'Puzzler Master Script'
  ClientHeight = 186
  ClientWidth = 302
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 8
    Width = 100
    Height = 13
    Caption = 'Macro execution Log'
  end
  object MSMemo1: tMSMemo
    Left = 8
    Top = 24
    Width = 281
    Height = 153
    Lines.Strings = (
      'Executing Puzzler 1')
    ScrollBars = ssBoth
    TabOrder = 0
    Text = 'Executing Puzzler 1'
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,ExitScript
Show>Dialog1

GetWindowHandle>Puzzler Master Script,hWndParent
FindObject>hWndParent,tMSMemo,,1,hWnd,X1,Y1,X2,Y2,result

Macro>%SCRIPT_DIR%\puzzler1.scp
Wait>5

ObjectSendKeys>hWnd,VK35,%CRLF%%CRLF%Executing Puzzler 2
Macro>%SCRIPT_DIR%\puzzler2.scp
Wait>5

ObjectSendKeys>hWnd,VK35,%CRLF%%CRLF%Executing Puzzler 3
Macro>%SCRIPT_DIR%\puzzler3.scp

Label>EndOfScriptLoop
  Wait>1
Goto>EndOfScriptLoop

SRT>ExitScript
  Exit>0
END>ExitScript



Puzzler 1, 2, 3 etc.

Code: Select all

GetWindowHandle>Puzzler Master Script,hWndParent
FindObject>hWndParent,tMSMemo,,1,hWnd,X1,Y1,X2,Y2,result
StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
ObjectSendKeys>hWnd,VK35,%CRLF%Ping number %kk%
If>kk>4
  Wait>1
  //Send this message to a dialog     %script_file% Complete
  ObjectSendKeys>hWnd,VK35,%CRLF%%script_file% Complete
  Exit>0
EndIf
Wait>1
Goto>Loop

Same solution with time stamp.

Master Script

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  Caption = 'Puzzler Master Script'
  ClientHeight = 186
  ClientWidth = 302
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 8
    Width = 100
    Height = 13
    Caption = 'Macro execution Log'
  end
  object MSMemo1: tMSMemo
    Left = 8
    Top = 24
    Width = 281
    Height = 153
    ScrollBars = ssBoth
    TabOrder = 0
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,ExitScript
Show>Dialog1

GetWindowHandle>Puzzler Master Script,hWndParent
FindObject>hWndParent,tMSMemo,,1,hWnd,X1,Y1,X2,Y2,result

Gosub>GetTime
ObjectSendKeys>hWnd,VK35,%varTime%: Executing Puzzler 1
Macro>%SCRIPT_DIR%\puzzler1.scp
Wait>5

Gosub>GetTime
ObjectSendKeys>hWnd,VK35,%CRLF%%CRLF%%varTime%: Executing Puzzler 2
Macro>%SCRIPT_DIR%\puzzler2.scp
Wait>5

Gosub>GetTime
ObjectSendKeys>hWnd,VK35,%CRLF%%CRLF%%varTime%: Executing Puzzler 3
Macro>%SCRIPT_DIR%\puzzler3.scp
Gosub>GetTime
ObjectSendKeys>hWnd,VK35,%CRLF%%CRLF%%varTime%: Done!

Label>EndOfScriptLoop
  Wait>1
Goto>EndOfScriptLoop

SRT>GetTime
  VBEval>Now,varTime
END>GetTime

SRT>ExitScript
  Exit>0
END>ExitScript


Puzzler 1, 2, 3 etc.

Code: Select all

GetWindowHandle>Puzzler Master Script,hWndParent
FindObject>hWndParent,tMSMemo,,1,hWnd,X1,Y1,X2,Y2,result
StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
VBEval>Now,varTime
ObjectSendKeys>hWnd,VK35,%CRLF%%varTime%: Ping number %kk%
If>kk>4
  Wait>1
  //Send this message to a dialog     %script_file% Complete
  VBEval>Now,varTime
  ObjectSendKeys>hWnd,VK35,%CRLF%%varTime%: %script_file% Complete
  Exit>0
EndIf
Wait>1
Goto>Loop

Last edited by Rain on Sun Oct 06, 2013 4:14 pm, edited 2 times in total.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Oct 06, 2013 2:50 pm

This one will only display one message at a time.

Master Script

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize, biMaximize]
  Caption = 'Puzzler Master Script'
  ClientHeight = 38
  ClientWidth = 302
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 8
    Top = 8
    Width = 281
    Height = 21
    TabOrder = 8
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,ExitScript
Show>Dialog1


Macro>%SCRIPT_DIR%\puzzler1.scp
Wait>5


Macro>%SCRIPT_DIR%\puzzler2.scp
Wait>5


Macro>%SCRIPT_DIR%\puzzler3.scp
SetControlText>Puzzler Master Script,TEdit,1,Done!

Label>EndOfScriptLoop
  Wait>1
Goto>EndOfScriptLoop

SRT>ExitScript
  Exit>0
END>ExitScript
Puzzler 1, 2, 3 etc.

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
SetControlText>Puzzler Master Script,TEdit,1,Ping number %kk%
If>kk>4
  Wait>1
  //Send this message to a dialog     %script_file% Complete
  SetControlText>Puzzler Master Script,TEdit,1,%script_file% Complete
  Exit>0
EndIf
Wait>1
Goto>Loop

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

Post by JRL » Mon Oct 07, 2013 12:56 am

@Rain,

Great scripts. I like the last much better than your first and its simpler than the second and third. However, was hoping to see that dialog information displayed on a label rather than in a memo box.

Not trying to make you work too hard for a few rep points (which so far are going to be yours anyway) so if you have a notion how to make some changes to your last (master) script to accomplish that I'll accept an explanation rather than a whole new script. Though a new script might be easier for others to follow.



@Everyone else,

Still accepting solutions for this puzzler. Rain's got a great script but as we saw in the last puzzler there is always another way.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Oct 07, 2013 3:18 pm

I can't come up with a way to dynamically update a Label from another script using the Macro command...because the TLabel is not an object like the edit and memo boxes. I could have each script to be executed create a dialog with a label and embed it in to the master scripts dialog but that's an ugly solution.

Maybe you know something I don't and gonna share it when this contest ends.

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

Post by JRL » Mon Oct 07, 2013 3:48 pm

Rain wrote:...because the TLabel is not an object like the edit and memo boxes.
Yep. Absolutely correct. Labels are weird critters that are not like other window objects and they can not be accessed using SetControlText>....directly. Labels are even missing some event properties compared to other window text objects like TEdit and TMemo.

Rain wrote:...gonna share it when this contest ends
Unless someone else shares it first.

Puzzling isn't it.

Might be a hint up there somewhere.

hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

Post by hoangvo81 » Mon Oct 07, 2013 11:30 pm

will this be allow in the puzzler1,2,3 script?

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
//setcontroltext>Puzzler Master Script,TEdit,1,Ping number %kk%
SetObjectText>obj,Ping Number %kk%
ObjectSendKeys>obj,a
If>kk>4
  Wait>1
  //Send this message to a dialog     %script_file% Complete
  //SetControlText>Puzzler Master Script,TEdit,1,%script_file% Complete
  SetObjectText>obj,%Script_file% Complete
  ObjectSendKeys>obj,a
  
  Exit>0
EndIf
Wait>1
Goto>Loop

the portion: setObjectText
and ObjectSendKeys

hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

Post by hoangvo81 » Mon Oct 07, 2013 11:45 pm

hoangvo81 wrote:will this be allow in the puzzler1,2,3 script?

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
//setcontroltext>Puzzler Master Script,TEdit,1,Ping number %kk%
SetObjectText>obj,Ping Number %kk%
ObjectSendKeys>obj,a
If>kk>4
  Wait>1
  //Send this message to a dialog     %script_file% Complete
  //SetControlText>Puzzler Master Script,TEdit,1,%script_file% Complete
  SetObjectText>obj,%Script_file% Complete
  ObjectSendKeys>obj,a
  
  Exit>0
EndIf
Wait>1
Goto>Loop

the portion: setObjectText
and ObjectSendKeys
if the above is allow:
MasterScript

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 1163
  Top = 273
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Puzzle Masterscript'
  ClientHeight = 25
  ClientWidth = 169
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 8
    Width = 32
    Height = 13
    Caption = ''
  end
  object MSButton1: tMSButton
    Left = 8
    Top = 32
    Width = 75
    Height = 25
    Caption = 'MSButton1'
    TabOrder = 0
    Visible = False
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1
SRT>SetLabel
  GetDialogProperty>Dialog1,MSButton1,Caption,rCap
  SetDialogProperty>Dialog1,Label1,Caption,%rCap%
END>SetLabel

Adddialoghandler>Dialog1,MSButton1,onClick,SetLabel
AddDialogHandler>Dialog1,,OnClose,ExitScript

show>Dialog1
getwindowhandle>Puzzle Masterscript,whndl
findobject>whndl,tMSButton,,1,objHndl,tx,ty,bx,by,rscaption
'find the button
 
Macro>%SCRIPT_DIR%\puzzler1.scp /obj=%objHndl%
wait>5

Macro>%SCRIPT_DIR%\puzzler2.scp /obj=%objHndl%
wait>5

Macro>%SCRIPT_DIR%\puzzler3.scp /obj=%objHndl%
wait>5

SetDialogProperty>Dialog1,Label1,Caption,Done!!!
'display final message that all done

Label>loopUntilDone
    wait>1
    Goto>loopUntilDone
    
SRT>ExitScript
    exit>0
END>ExitScript
Puzzle 1,2,3

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
//setcontroltext>Puzzler Master Script,TEdit,1,Ping number %kk%
SetObjectText>obj,Ping Number %kk%
Pushbutton>Puzzle Masterscript,Ping Number %kk%
If>kk>4
  Wait>1
  //Send this message to a dialog     %script_file% Complete
  //SetControlText>Puzzler Master Script,TEdit,1,%script_file% Complete
  SetObjectText>obj,%Script_file% Complete
  PushButton>Puzzle Masterscript,%Script_file% Complete
  
  Exit>0
EndIf
Wait>1
Goto>Loop

have a button not visible in the master script, send that objhndl value to teh called script puzzler1,2,3
puzzler1,2,3 will set the obj's text and push that button
which trigger back to master script's handler for onclick to grab the text and set it to the label.

i also tried using the title of the window. The master script has 1 less line (no need to findobject since getwindowhandle will give us teh control handle)
and instead of onclick for the button, it will be onkeypress for the dialog to trigger the setlabel.

i cannot find a way to send the text directly from the puzzler1,2,3 since the label is not treated as an object. - and you dont need the button if using the caption of the dialog as the message holder.

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

Post by JRL » Tue Oct 08, 2013 5:25 am

hoangvo81,

Great concept and execution!

You are correct that the information cannot be sent directly to the label so sending it to an invisible button and then transferring it from the invisible button to the label when the button is clicked is a workable method. But it does require that the button be pressed.

Anyone have a different concept for how to solve this? Two good entrants so far. I still think there is an easier yet similar method.

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

Post by Grovkillen » Tue Oct 08, 2013 7:15 am

Not a full solution (didn't have time) but I sometimes do the "OnKeyPress" event to retrieve status from other scripts. In this case I would use the number keys to go from 0, 1, 2... 9 (10% steps) and press D when done. Please look in the sample code below:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 255
  Top = 104
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 53
  ClientWidth = 293
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 8
    Width = 101
    Height = 37
    Caption = 'Label1'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -32
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    WordWrap = True
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnKeyPress,SET_INFO

Show>Dialog1,r

SRT>SET_INFO
  SetDialogProperty>Dialog1,Label1,Caption,%SET_INFO_KEY%
END>SET_INFO
In other words: the sub-scripts would press keys for each step they make and the master-script would listen for key presses....
Let>ME=%Script%

Running: 15.0.27
version history

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

Post by Grovkillen » Tue Oct 08, 2013 8:29 am

Okay, I made some small changes. You could have the Master just lookin for one key (example below that key is "p", 112). Just keep pressing the p-key and the label will step 1% each press until it hit more than 100% which by then it change the label to Done!

Code: Select all

Let>PROGRESS=0

Dialog>Dialog1
object Dialog1: TForm
  Left = 255
  Top = 104
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 53
  ClientWidth = 293
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 8
    Width = 101
    Height = 37
    Caption = 'Label1'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -32
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    WordWrap = True
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnKeyPress,SET_INFO

Show>Dialog1,r

SRT>SET_INFO
    If>SET_INFO_KEY=112
        Let>PROGRESS=%PROGRESS%+1
        If>PROGRESS>100
            SetDialogProperty>Dialog1,Label1,Caption,Done!
        Else>
            SetDialogProperty>Dialog1,Label1,Caption,%PROGRESS%%
        Endif>
    Endif>
END>SET_INFO

Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Tue Oct 08, 2013 3:07 pm

The solution was in front of me all this time. :oops: Here you go.


Master Script

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Puzzler Master Script'
  ClientHeight = 26
  ClientWidth = 302
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 8
    Width = 32
    Height = 13
    Caption = 'Label1'
  end
  object Edit1: TEdit
    Left = 280
    Top = 0
    Width = 17
    Height = 21
    AutoSelect = False
    Color = clWhite
    TabOrder = 0
    Visible = False
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,ExitScript
AddDialogHandler>Dialog1,Edit1,OnChange,UpdateLabel
Show>Dialog1


Macro>%SCRIPT_DIR%\puzzler1.scp
Wait>5


Macro>%SCRIPT_DIR%\puzzler2.scp
Wait>5


Macro>%SCRIPT_DIR%\puzzler3.scp
Wait>1
SetDialogProperty>Dialog1,Label1,Caption,Done!

Label>EndOfScriptLoop
  Wait>1
Goto>EndOfScriptLoop

SRT>ExitScript
  Exit>0
END>ExitScript

SRT>UpdateLabel
  GetDialogProperty>Dialog1,Edit1,Text,Res
  SetDialogProperty>Dialog1,Label1,Caption,%Res%
END>UpdateLabel

Puzzler 1, 2, 3 etc.

Code: Select all

StringReplace>script_file,%script_dir%\,,script_file
Let>kk=0
Label>Loop
Add>kk,1
Let>RP_WAIT=1
Let>RP_Windowmode=0
RunProgram>cmd /c ping 127.0.0.1 -n 1
//Send this message to a dialog     Ping number %kk%
SetControlText>Puzzler Master Script,TEdit,1,Ping number %kk%
If>kk>4
  Wait>1
  //Send this message to a dialog     %script_file% Complete
  SetControlText>Puzzler Master Script,TEdit,1,%script_file% Complete
  Exit>0
EndIf
Wait>1
Goto>Loop


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

Post by JRL » Tue Oct 08, 2013 4:19 pm

@Rain,

You have hit on the precise method I was looking for, Almost note for note the same song I played before posting this puzzler. We'll see if any more good ideas come in before Friday.

@Grovkillen,

I'm impressed. Your idea is different than what anyone else has come up with and very workable. One caveat I see is that the dialog must have focus when the subordinate script presses a key. This means the subordinate script would need three lines of code for each info transfer, a setfocus to the dailog, the key press and then possibly a setfocus back to the working window. One other caveat is that the key codes are not particularly descriptive. They would basically leave a marker that one could use to determine where in the subordinate scripts the last key press occurred.

@Everyone,

There's always another way. Anybody have any other good ideas. For example using Libfunc> and SendMessage or maybe using email?

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