Can't close dialog after sub starts

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

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

Can't close dialog after sub starts

Post by JRL » Sun Sep 26, 2010 12:06 am

Macro Scheduler version 12.0.8; Windows XP SP2

The following script is behaving in a way I don't understand. If you start the script then press the "Ok" button, you will no longer be able to close the dialog and thus stop the script unless you're running it from the editor, in which case the dialog closes and the script stops as I would expect.

Another odd thing is that at first I mistakenly left out the VBSTART/VBEND block and yet the VBEVAL timer line seemed to work. At least the script timed out. Help for VBStart still says:
If you wish to evaluate VBScript expressions in your scripts you will need a VBSTART/VBEND block at the start of your script even if it contains no code.
Any thoughts? What am I missing?
Thanks,
Dick

Code: Select all

VBSTART
VBEND

//variable for the timeout period
Let>Waiting=5

Dialog>Dialog1
object Dialog1: TForm
  Left = 329
  Top = 205
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Do Something'
  ClientHeight = 140
  ClientWidth = 325
  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 = 40
    Top = 16
    Width = 258
    Height = 24
    Caption = 'We are about to do something.'
    ParentFont = False
  end
  object Label2: TLabel
    Left = 40
    Top = 48
    Width = 140
    Height = 24
    Caption = 'Please pick Ok...'
    ParentFont = False
  end
  object MSButton1: tMSButton
    Left = 128
    Top = 98
    Width = 75
    Height = 25
    Caption = 'Ok'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

//Dialog handler to exit the script when the dialog closes
AddDialogHandler>Dialog1,,OnClose,Quit

//Dialog handler to start "Process" subroutine when the Ok button is pressed
AddDialogHandler>Dialog1,msButton1,OnClick,Process

Show>dialog1,res1

SRT>Quit
  Exit>0
END>Quit

SRT>Process
  //Change the dialog text and remove the Ok button
  SetDialogProperty>Dialog1,Label1,Caption,Waiting for Something.
  SetDialogProperty>Dialog1,Label2,Caption,Please be patient...
  SetDialogProperty>Dialog1,,Caption,Waiting...
  SetDialogObjectVisible>Dialog1,msButton1,0
  SetFocus>Waiting...

  //Timer start
  VBEval>Timer,StartTime

  //Loop until "TotalTime" surpasses "Waiting"
  Label>WaitLoop
    Wait>0.01
    VBEval>Timer-%StartTime%,TotalTime
    If>TotalTime>Waiting
      SetDialogProperty>Dialog1,Label1,Caption,        Thanks for waiting
      SetDialogProperty>Dialog1,Label2,Caption,              Goodbye...
      Wait>2
      Exit>0
    EndIF
  Goto>WaitLoop
END>Process

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

Post by Marcus Tettmar » Mon Sep 27, 2010 9:03 am

Try this instead of your modal Show:

Show>dialog1
Label>idleloop
Wait>0.02
Goto>idleloop

When run in the debugger any modal shows are actually NOT modal. If they were you wouldn't be able to use the debugger, because the dialog would prevent the editor getting the focus. So instead the debugger sets up a loop like the above, making it SEEM modal in that the script waits until you close the dialog. But a side effect is other events can fire. In your modal dialog the event fired by the OK button had to complete before another event could process.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by JRL » Mon Sep 27, 2010 8:02 pm

Good to know that dialog modality is still a factor. I assumed that when you jump to a subroutine so line resolution is occurring, the script was then capable of processing other event functions such as AddDialogHandler and OnEvent.

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