Is Dialog open

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
katalonija2
Junior Coder
Posts: 21
Joined: Thu Mar 10, 2011 6:49 pm

Is Dialog open

Post by katalonija2 » Sat Mar 26, 2011 5:39 pm

Is there some method for checking if the dialog is open?
I can use flag and to reset flag when dialog is closed,but is there another way or property?

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

Post by JRL » Mon Mar 28, 2011 2:37 am

Technically, once the dialog block has been evaluated, the dialog is "open" even though until you either Show> or SetFocus> to the dialog it will not be "visible"

If you have Macro Scheduler version 12, it will be easy to check to see if the dialog is visible or not by using the GetDialogProperty> function then testing the result variable to see if it is "True" (dialog is visible) or "False" (dialog is not visible).
GetDialogProperty>Dialog1,,visible,DlgVisibility

The following script demos what I'm talking about. Step through by pressing F8 in the editor to see the results.

Code: Select all

Dialog>Dialog1
EndDialog>Dialog1

//The dialog block has been evaluated but Show> has not been called
Let>WIN_USEHANDLE=1
  IfWindowOpen>Dialog1.handle
    MDL>dialog1 is open
  Else
    MDL>dialog1 is not open
  EndIf
  
  GetDialogProperty>Dialog1,,visible,DlgVisibility
  
  If>DlgVisibility=True
    MDL>dialog1 is visible
  EndIf
  
  If>DlgVisibility=False
    MDL>dialog1 is not visible
  EndIf

show>dialog1

//The dialog block has been evaluated and Show> has been called
  IfWindowOpen>Dialog1.handle
    MDL>dialog1 is open
  Else
    MDL>dialog1 is not open
  EndIf
  
  GetDialogProperty>Dialog1,,visible,DlgVisibility
  
  If>DlgVisibility=True
    MDL>dialog1 is visible
  EndIf
  
  If>DlgVisibility=False
    MDL>dialog1 is not visible
  EndIf
  
CloseDialog>dialog1

//The dialog has been closed
  IfWindowOpen>Dialog1.handle
    MDL>dialog1 is open
  Else
    MDL>dialog1 is not open
  EndIf
  
  GetDialogProperty>Dialog1,,visible,DlgVisibility
  
  If>DlgVisibility=True
    MDL>dialog1 is visible
  EndIf
  
  If>DlgVisibility=False
    MDL>dialog1 is not visible
  EndIf

katalonija2
Junior Coder
Posts: 21
Joined: Thu Mar 10, 2011 6:49 pm

Post by katalonija2 » Mon Mar 28, 2011 5:44 am

Ok, so i am limited in using dialog in external subroutine.

First as in a good manner,include command should be as declaration in programs language, on start of program...
Then as compromize, i need flag in subroutine that is global, to keep me info about first/nofirst entry in subroutine...

I want to escape from "dialog is already defined", or similar error message.

Also by first call of subroutine i "opened" all dialogs in subroutine.
So names of dialogs must be unique if i want them to be global.
Ok,like srt prefix in name of dialog ....srtDialog1.......

I am thinking of some property as a flag of evaluation of dialog...
If dialog is not evaluated, then GetDialogProperty(some of available properties) will leave variable undefined.
And
GetDialogProperty>Dialog11,,property,try
will leave try as try...
So
Let>trt=%try%
if>trt=%try%
MessageModal>dialogexist
else
MessageModal>dialognotexist
endif

What to use as a property?
Top,Font,color...
What is must be property in dialog suitable for this?

P.S. And i am aware of that this will not work in Let>VAREXPLICIT=1
systems...

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

Post by JRL » Mon Mar 28, 2011 3:33 pm

I am thinking of some property as a flag of evaluation of dialog...

Code: Select all

GetDialogProperty>dialog1,,Caption,res
Assigned>res,Ares
Choose any property you want using the above technique. If Dialog1 block has been evaluated then variable "res" will have a value and variable "Ares" will be "True". Otherwise "res" will have no value and "Ares" will be false.

One caveat is that the name of variable "res" will need to change if you do multiple tests. Once a variable has a value, Assigned> will thereafter resolve that variable's existence as "True". In other words, you can't destroy a variable once it has been created.
First as in a good manner,include command should be as declaration in programs language, on start of program...
I'm not sure I understand what you're asking. If you mean that you have scripts that you are importing into your code using the Include> function and that those scripts have dialogs and that those dialog blocks have the same names. For Example they are all Dialog1. I believe you will need to make all of the dialog block names unique.

katalonija2
Junior Coder
Posts: 21
Joined: Thu Mar 10, 2011 6:49 pm

Post by katalonija2 » Tue Mar 29, 2011 5:39 pm

Thank you a lot...
You understand everything right.

Thank you for assigned command, i didnot know that.

And about problem of multiple testing for opened dialog,i will solve that with protocol that Ares will be named DLGdialogname_on.

In that way dialog can be in if then else structure...

Code: Select all

GetDialogProperty>dialog1,,Caption,res
Assigned>res,DLG_Dialog1_on
if>%DLG_Dialog1_on%
else
Dialog>Dialog1
......
.....
EndDialog>Dialog1
endif

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

Post by JRL » Tue Mar 29, 2011 6:02 pm

I think you meant
GetDialogProperty>dialog1,,Caption,res
Assigned>res,DLG_Dialog1_on
if>%DLG_Dialog1_on%
=True
else
Dialog>Dialog1
......
.....
EndDialog>Dialog1
endif

Glad its working for you.

katalonija2
Junior Coder
Posts: 21
Joined: Thu Mar 10, 2011 6:49 pm

Post by katalonija2 » Thu Mar 31, 2011 4:49 am

I made mistake in steps

Code: Select all

GetDialogProperty>dialog1,,Caption,DLG_Dialog1_on
Assigned>DLG_Dialog1_on,res
if>%res%=True 
else
Dialog>Dialog1
......
endif
In this way i can test it as many times as i want.

Thank you for marking me that res has virgin behaivour in assigned command

katalonija2
Junior Coder
Posts: 21
Joined: Thu Mar 10, 2011 6:49 pm

Post by katalonija2 » Tue Apr 12, 2011 11:01 am

This works if Let>Localvars=0
but if it is not, then, for some reason, getdialogproperty dont work as usual.

So solution is in PIG or TAE method (try and error)
To move Let>Localvars=1 after diagnostic lines for dialog existance.
And other important variables, as count variables.

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

Post by JRL » Tue Apr 12, 2011 10:18 pm

This works if Let>Localvars=0
but if it is not, then, for some reason, getdialogproperty dont work as usual.
After a little testing I see that you have a point though I think your diagnosis is a little off. GetDialogProperty> is working fine when LocalVars is set to 1, but the Assigned> function doesn't report as I'd expect when its in a subroutine and LocalVars is 1.

I would expect that when LocalVars is 1 and Assigned> is called within a subroutine to test a variable that has a value that was assigned in that subroutine, the test result would be "TRUE". But it turns out that under this condition the test result is "FALSE".

For example:

Code: Select all

Let>Localvars=1
GoSub>TestVar

SRT>TestVar
  Let>var=1
  Assigned>var,result
  MDL>result
END>TestVar
With LocalVar set to 0 the Assigned> test result will be "TRUE" but if it is set to 1 the test result will be "FALSE". This would make sense to me if the test was done outside of the subroutine... that is, after all, why "LocalVars" was invented.


There is another way to test to see if a variable has a value.

The way that alphanumerics strings work in Macro Scheduler is that they are simple text strings until some process assigns that alphanumeric string a value. This means that if you test text string "var" and it has no value it will be equal to the text characters "v" "a" "r". You can test the string by placing it in a complex expression.

Code: Select all

If>var={"var"}
  //Do this if the string "var" is equal to the text "var"
Else
  //Do this if the string "var" has been assigned a value so it is no longer
  //equal to the text "var".
EndIf
So a sample that will do what I think you are looking for would have to test the string using a complex expression. Something like:

Code: Select all

Let>Localvars=1

Label>Loop
  GoSub>MakeDialog
Goto>Loop

SRT>MakeDialog
  //Get the dialog property (as suggested before) to determine if the dialog already exists.
  GetDialogProperty>dialog1,,Caption,var
  //Test var for a value
  If>var={"var"}
    //The text string "var" is equal to the text string "var"
    //Create the dialog if it does not already exist
    Dialog>Dialog1
    --------
    EndDialog>Dialog1
    AddDialogHandler>Dialog1,,Onclose,Abort
    Show>Dialog1
  else
    //The text string "var" has been assigned a value
    //Do not create the dialog
  endif
END>MakeDialog

Of course this test will fail if the value of "var" ever gets set back to the text string "var". Also note that the text tests are case sensitive. "VAR" does not equal "var" does not equal "vAr" etc.


Hope this all makes sense.
Dick

katalonija2
Junior Coder
Posts: 21
Joined: Thu Mar 10, 2011 6:49 pm

Post by katalonija2 » Wed Apr 13, 2011 5:02 pm

I used that at first, as newbe, but now, i am avoiding that.
In the case of getdialogproperties, i can use it before i set localvar.

In close relationship with this is how to get exact number of subroutine parameters.
First time subroutinename_var_count will do the job.
But next time wount.
reset of variable does not exist, but to use structure like
set localvar
gosub
reset localvar
to conserve one variable subroutinename_var_count is to much...


//set and reset are used as let....=1 let....=0

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