Dialog Box -> FileOpen

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Hardware_Tester
Pro Scripter
Posts: 58
Joined: Mon Jun 27, 2005 7:03 am
Location: Switzerland

Dialog Box -> FileOpen

Post by Hardware_Tester » Fri Aug 05, 2005 1:53 pm

I am working on a Script which needs some starting variables, which I am collecting from a DialogBox. There I use a FileOpen-Dialog. My Question is now:

1. How can I get this data? I was looking at the variables in the Watchlist, but it didn't apear.

2. Could this Path be displayed in the editbox?

My Script:
Dialog>Start_Config
Caption=Testconfig
Top=197
Width=373
Left=426
Height=204
Label=Number of O4LE,16,16
Label=Number of G4AI,136,16
Label=Licence for MOD600,16,72
Label=Licence for NSK600,136,72
Label=Select COM-Port,256,16
Label=Path to HMI,16,120
ComboBox=O4LE,16,32,97,0%CRLF%1%CRLF%2%CRLF%3
ComboBox=G4AI,136,32,97,0%CRLF%1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7
ComboBox=MOD600,16,88,97,0%CRLF%1
ComboBox=NSK600,136,88,97,0%CRLF%2%CRLF%4
Button=ETL Online,280,72,75,25,3
Button=ETL Offline,280,104,73,25,2
Button=Close,280,136,73,25,1
ComboBox=COMport,256,32,97,1%CRLF%2
Edit=PathHMI,16,136,137,Select the Path to HMI
Button=Browse,160,136,75,25,0
Filebrowse=Browse,PathHMI,Application (*.exe)|*.exe|,open,C:\
EndDialog>Start_Config

Show>Start_Config
Message>%CWD%
Label>MainLoop
GetDialogAction>Start_Config,result
If>result=1
CloseDialog>Start_Config
goto>End
Else
...

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Aug 05, 2005 3:44 pm

Hi,

It is in variable Start_Config.PathHMI

Here's a simple example showing how it works:

Dialog>Dialog1
Caption=Dialog1
Top=112
Width=282
Left=16
Height=118
Edit=txtBrowse,24,24,121,
Button=&Browse,152,24,75,25,10
Button=OK,24,56,75,25,2
FileBrowse=&Browse,txtBrowse,Text Files|*.txt
EndDialog>Dialog1

Show>Dialog1
Label>aloop
GetDialogAction>Dialog1,r
If>r=2,exit
Goto>aloop
Label>exit
CloseDialog>Dialog1
MessageModal>Dialog1.txtBrowse

When you hit OK it will tell you what filename was selected.
MJT Net Support
[email protected]

Hardware_Tester
Pro Scripter
Posts: 58
Joined: Mon Jun 27, 2005 7:03 am
Location: Switzerland

Post by Hardware_Tester » Fri Aug 19, 2005 2:53 pm

Hi Again

I could solfe all problems, but then I generated an EXE, and the Mistery began:

- At single click the Buttons don't react
- Filebrowse works only, when the Comboboxes have another Value then 0
- When I click in the right upper X to close the windows, strange things happen.

My Code:
There are two additional labels, but they contain only additional code for setting stuff in another Program.

Dialog>Start_Config
Caption=Testconfig
Top=197
Width=356
Left=426
Height=151
Label=Number of O4LE,16,16
Label=Number of G4AI,136,16
Label=Path to HMI,16,64
ComboBox=O4LE,16,32,97,0%CRLF%1%CRLF%2%CRLF%3
ComboBox=G4AI,136,32,97,0%CRLF%1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7
Button=All cases,256,16,75,25,2
Button=Single case,256,48,73,25,3
Button=Close,256,80,73,25,1
Edit=exeBrowse,16,80,137,
Button=&Browse,160,80,75,25,0
Filebrowse=&Browse,exeBrowse,Application|*.exe
EndDialog>Start_Config

//Nicht modaler Dialog-Aufruf -> Fenster steht hinter Meldungen
Show>Start_Config
Label>MainLoop
//Buttonabfrage
GetDialogAction>Start_Config,result

//Variablendownload
Let>NumO4LE=%Start_Config.O4LE%
Let>NumG4AI=%Start_Config.G4AI%

//Prüfung von HMIpfad
Let>HMIpath=%Start_Config.exeBrowse%
Let>HMIpathgood=1
Position>:\,HMIpath,1,HMIpathgood
If>HMIpathgood=0,reset
Position>.exe,HMIpath,1,HMIpathgood
If>HMIpathgood=0,reset
Position>HMI,HMIpath,1,HMIpathgood
If>HMIpathgood=0,reset

//Verzweigung für die Buttons
If>result=1,End
If>result=2,Auto
If>result=3,Single
goto>reset


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Autoconfig
Label>Auto
//HMI starten und Aufruf Grundeinstellungen
gosub>startHMI
gosub>firstrun

//Number of O4LE
let>NumO4LE=0
//Number of G4AI
let>NumG4AI=0
//Hilfsvariable: anzahl Boards
let>i=0
//Zählvariable 1
let>z=0
//Zählvariable 2
let>y=0

repeat>y
repeat>z
//Subroutine configure
gosub>configure


//Autoroutine, more Infos in Nassi-Schneidermann diagram in the Docu
let>NumO4LE=NumO4LE+1
let>i=i+1
if>{(%i%=8) OR (%NumO4LE%=4)}
let>z=1
else
endif>
until>z=1
let>z=0
let>i=i-NumO4LE
let>NumO4LE=0
let>NumG4AI=NumG4AI+1
let>i=i+1
if>i=8
let>y=1
else
endif>
until>y=1
messagemodal>Finished, the files are in the same directory as the macro in a folder with the actual date. There is also a File called ETL600_default.et6, which is a working file.



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Einzelconfig
Label>Single
Let>r=%NumO4LE%
Let>s=%NumG4AI%
Let>r=%r%+%s%
If>%r%>7
Message>Not more then 7 interface boards G4AI or O4LE are allowed
goto>reset
else
//HMI starten und Aufruf Grundeinstellungen
gosub>startHMI
gosub>firstrun
//Rest konfigurieren
gosub>configure
endif>
goto>reset

//reset Dialog and restart
Label>reset
ResetDialogAction>Start_Config
goto>MainLoop

//exit macro
Label>End
CloseDialog>Start_Config

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Aug 19, 2005 3:45 pm

My goodness - where to start!

1. Modal Result 2 is sent when the close button is pressed. So you should probably change the modal value of your close button to 2 so that both do the same thing. Therefore you do not need to issue the CloseDialog command since a result of 2 does this automatically.

2. The script jumps about all over the place - it is very hard to understand what you are trying to do. The control loop is confusing and it is no surprise that you may have to click a button more than once before the script notices that it has been pressed. It makes more sense to always check the state of the buttons right at the start of the loop just after GetDialogAction. Then and only when appropriate get the data from the fields on the dialog. That way the action loop is prioritized to process button presses first and foremost and the script will only do any further processing if a button is pressed. We tell the script what to do if the button is pressed.

4. Subroutines startHMI, firstrun and Configure do not exist.

I have rearranged your script as below and this works. I have commented out the calls to subroutines that don't exist. I have tried to understand what you are aiming to achieve and reorganised your script appopriately but I may have misunderstood what you are doing so this might not be perfect, but it should demonstrate a more logical approach. Notice that I have changed the button values to 2, 10 and 20. 2 is the close button - matches the close button of the dialog and then 10 and 20 for the 'action' buttons. This makes it easier to differentiate and do something if either are pressed - as happens here. I have removed all the Labels/Gotos and changed to Subroutines. When a button is pressed you just have to call a subroutine. Instead of jumping to Reset all the time - which gets confusing there is just one jump back to the start of the loop after the buttons are checked:

Dialog>Start_Config
Caption=Testconfig
Top=197
Width=356
Left=426
Height=151
Label=Number of O4LE,16,16
Label=Number of G4AI,136,16
Label=Path to HMI,16,64
ComboBox=O4LE,16,32,97,0%CRLF%1%CRLF%2%CRLF%3
ComboBox=G4AI,136,32,97,0%CRLF%1%CRLF%2%CRLF%3%CRLF%4%CRLF%5%CRLF%6%CRLF%7
Button=All cases,256,16,75,25,10
Button=Single case,256,48,73,25,20
Button=Close,256,80,73,25,2
Edit=exeBrowse,16,80,137,
Button=&Browse,160,80,75,25,0
Filebrowse=&Browse,exeBrowse,Application|*.exe
EndDialog>Start_Config

//Nicht modaler Dialog-Aufruf -> Fenster steht hinter Meldungen
Show>Start_Config
Label>MainLoop
//Buttonabfrage
GetDialogAction>Start_Config,result

//FIRST see which button was pressed
If>result=2,End
If>result>9
//Variablendownload
Let>NumO4LE=%Start_Config.O4LE%
Let>NumG4AI=%Start_Config.G4AI%

//Prüfung von HMIpfad
Let>HMIpath=%Start_Config.exeBrowse%
Let>HMIpathgood=1
Position>:\,HMIpath,1,HMIpathgood
//If>HMIpathgood=0,reset
Position>.exe,HMIpath,1,HMIpathgood
//If>HMIpathgood=0,reset
Position>HMI,HMIpath,1,HMIpathgood
//If>HMIpathgood=0,reset

if>result=10,Auto
If>result=20,Single

ResetDialogActioN>Start_Config
EndIf
Goto>MainLoop


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Autoconfig
SRT>Auto
//HMI starten und Aufruf Grundeinstellungen
//gosub>startHMI
//gosub>firstrun

//Number of O4LE
let>NumO4LE=0
//Number of G4AI
let>NumG4AI=0
//Hilfsvariable: anzahl Boards
let>i=0
//Zählvariable 1
let>z=0
//Zählvariable 2
let>y=0

repeat>y
repeat>z
//Subroutine configure
//gosub>configure

//Autoroutine, more Infos in Nassi-Schneidermann diagram in the Docu
let>NumO4LE=NumO4LE+1
let>i=i+1
if>{(%i%=8) OR (%NumO4LE%=4)}
let>z=1
else
endif>
until>z=1
let>z=0
let>i=i-NumO4LE
let>NumO4LE=0
let>NumG4AI=NumG4AI+1
let>i=i+1
if>i=8
let>y=1
else
endif>
until>y=1
messagemodal>Finished, the files are in the same directory as the macro in a folder with the actual date. There is also a File called ETL600_default.et6, which is a working file.
GoSub>Single
END>Auto

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Einzelconfig
SRT>Single
Let>r=%NumO4LE%
Let>s=%NumG4AI%
Let>r=%r%+%s%
If>%r%>7
Message>Not more then 7 interface boards G4AI or O4LE are allowed
else
//HMI starten und Aufruf Grundeinstellungen
//gosub>startHMI
//gosub>firstrun
//Rest konfigurieren
//gosub>configure
endif>
END>Single

//exit macro
Label>End

If it is any help I would base a non-modal dialog script on the following skeleton:

DIALOG BLOCK
Show>Dialog
Label>mainloop
GetDialogAction
//check which button pressed
If>result=10,ButtonOneSubroutine
If>result=20,ButtonTwoSubroutine
If>result=2,End
ResetDialogAction
Goto>mainloop
Label>end

SRT>ButtonOneSubroutine
End>ButtonOneSubroutine

SRT>ButtonTwoSubroutine
END>ButtonTwoSubroutine

This should form the basis of most non-modal dialog scripts.

Hope this helps.
MJT Net Support
[email protected]

Hardware_Tester
Pro Scripter
Posts: 58
Joined: Mon Jun 27, 2005 7:03 am
Location: Switzerland

Post by Hardware_Tester » Sat Aug 20, 2005 2:02 pm

Thanks for the Help

I will try out this as soon as possible and then report, if it works. And now soe other Questions:

1. Is there a maximum length of the script?

The missing subroutines are Passage over 100 Lines, where I am working with Keyboard-strokes to configure something in a dialog.

And I have to add some 200 Lines more, to complete the script.



2. When it is finished, it will have to run for 10 Hours to complete the whole Autoconfig. Are there Time-Limitations for the Values?
Some of them I have to get out of the dialog Box and then using it until the end=10hours.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Sat Aug 20, 2005 2:05 pm

There are no length or time limitations. Scripts can be as long as you like and they will run for as long as you like.
MJT Net Support
[email protected]

Hardware_Tester
Pro Scripter
Posts: 58
Joined: Mon Jun 27, 2005 7:03 am
Location: Switzerland

Post by Hardware_Tester » Mon Aug 22, 2005 9:54 am

The script worked with some little corrections. Now my last question:

When I define a Variable in a Subroutine, can I use it in another subroutine which wasn't called by this subroutine, in other Words, which is independent?

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Aug 22, 2005 11:00 am

Variables have global scope. So wherever you declare it you can use it anywhere. So if you create a variable in a subroutine it will be visible anywhere in the script and in any other subroutines.
MJT Net Support
[email protected]

Hardware_Tester
Pro Scripter
Posts: 58
Joined: Mon Jun 27, 2005 7:03 am
Location: Switzerland

Post by Hardware_Tester » Mon Aug 22, 2005 5:11 pm

It wasn't my last question :(

When I run the script, sometimes a string in a file-open dialog isn't written completly, just the first single letter. The same happens also with the file-close dialog, where I do the exactly same.

Example:
String is: D:\Files\Macro_Building\Scripts\Testconfig600\22.08.05\ETL600_default.et6
written is:
d

The code
//File>open
Press ALT
Release ALT
Send>fo

//Wait open
WaitWindowOpen>Open

//send the path
Send>%defaultpath%

//open
Press Enter

//wait for opening the normal window
WaitWindowOpen>HMI600*

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Aug 22, 2005 5:35 pm

Maybe you just need to slow it down, or something else is removing focus. Try setting SK_DELAY to slow down the Send. But also check carefully that after it starts to send the text something isn't removing focus.
MJT Net Support
[email protected]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Aug 22, 2005 5:41 pm

Maybe releasing the ALT key too soon?

Try changing

FROM this:

Code: Select all

//File>open
Press ALT
Release ALT
Send>fo 
TO this:

Code: Select all

//File>open
Press ALT
Send>fo
Release ALT

OR
TO this:

Code: Select all

//File>open
Press ALT
Wait>1
Send>fo
Release ALT
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Hardware_Tester
Pro Scripter
Posts: 58
Joined: Mon Jun 27, 2005 7:03 am
Location: Switzerland

Post by Hardware_Tester » Tue Aug 23, 2005 10:37 am

@Bob Hansen: Thanks for jour solution, but I can be shure, that it works, because it worked fine everywhere - about 20 times in the script.

@support: I tried to set Focus to the windows just before opening, but this didn't worked. I'll try the other way tomorrow. Another solution could be to send it key by key, but I don't know how to separate the string.

Hardware_Tester
Pro Scripter
Posts: 58
Joined: Mon Jun 27, 2005 7:03 am
Location: Switzerland

Post by Hardware_Tester » Thu Aug 25, 2005 12:59 pm

Changing the variable helped. Another bug I had:

There were several popups which opened at the same time. MSched lost focus after that. So i had to set Focus to each single popup. But the strange thin is: All popups were named almost the same way:

Module O4LE at N**

At the wildcard was a number which changed.

When I set focus with

setfocus>module*

It didn't work. Why?

So I had to find out how many popups it where, depending on some variables and then doing this in a loop. A very complicated solution, just because MSched could not focus to the first popup with the matching name.

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