Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29271 Discussions

Automatically press a button at startup

tmcole
Beginner
943 Views
Is there a way to force a button to be pressed automatically when first running a program? I have a dialog box that has Run, Stop, and Restart and someone else needs to automatically have the Run button pushed when the program starts (they want to batch process a number of runs).
0 Kudos
8 Replies
Jugoslav_Dujic
Valued Contributor II
943 Views

There are various complicated ways; however, isn't it simpler that you provide e.g. a command-line switch which will skip the dialog and go into "invisible", or "batch" mode, e.g.

callGETARG(1, sArg)

if (TRIM(sArg).ne."/batch") then

0 Kudos
Jugoslav_Dujic
Valued Contributor II
943 Views

There are various complicated ways; however, isn't it simpler that you provide e.g. a command-line switch which will skip the dialog and go into "invisible", or "batch" mode, e.g.

callGETARG(1, sArg)

if (TRIM(sArg).ne."/batch") then

0 Kudos
Jugoslav_Dujic
Valued Contributor II
943 Views

There are various complicated ways; however, isn't it simpler that you provide e.g. a command-line switch which will skip the dialog and go into "invisible", or "batch" mode, e.g.

LOGICAL:: bOK
CHARACTER(20):: sArg

callGETARG(1, sArg)

if (TRIM(sArg) .ne. "/batch") then
b= DlgInit(...
bOK = DlgModal(Dlg) .EQ. IDOK
else
bOK = .TRUE.
end if

if (bOK) then
!Calculate as usual
end if

Jugoslav

0 Kudos
tmcole
Beginner
943 Views

Jugaslov,

I hear you, except the user wants the screen to appear as there is a lot of information regarding the run that is written out to a dialog box (that you helped me with a while back). So, I would appreciate the more complicated solution.

Tom

0 Kudos
Jugoslav_Dujic
Valued Contributor II
943 Views
I understand.
Then, as a variation on the same theme -- I assume you have a callback for "OK"/"Run" button rather than letting it close the dialog, right -- otherwise it wouldn't make sense:
...
b = DlgInit(IDD_DIALOG, Dlg)
b = DlgSetSub(Dlg, IDOK, OnExecute)
now, just define that the button's callback is the same as dialog-initialization callback:
if (trim(sArg) = "/batch")
b = DlgSet(Dlg, IDD_DIALOG, OnExecute)
end if
OnExecute will be started immediatelyafter DlgModal.
Jugoslav
0 Kudos
tmcole
Beginner
943 Views
Jugoslav,
Appreciate the help, but your solution is as clear as mud to me because of my lack of understanding of Visual Fortran coding. What is "OnExecute" and where is it defined? When you say "define that the button's callback is the same as dialog initialization callback", what button are you talking about? I have the following code:
PROGRAM W2_DIALOG
USE DFLOGM; USE MSCLIB
INTEGER :: RESULT
LOGICAL :: RSO_EXISTS=.FALSE.
TYPE (DIALOG) :: DLG
EXTERNAL RUN_W2
RESULT = DLGINIT (OUTPUT_DIALOG,DLG)
RESULT = DLGSET (DLG,STATUS,' Pending execution')
RESULT = DLGSET (DLG,RESTART, .FALSE.,DLG_ENABLE)
RESULT =DLGSET (DLG,STOP_EXECUTION,.FALSE.,DLG_ENABLE)
RESULT = DLGSETSUB (DLG,RUN, RUN_W2)
RESULT = DLGSETSUB (DLG,STOP_EXECUTION, RUN_W2)
RESULT = DLGSETSUB (DLG,RESTART, RUN_W2)
RESULT = DLGMODAL (DLG)
CALL DLGUNINIT (DLG)
END PROGRAM W2_DIALOG
where "RUN" is the button that I want pushed that starts the model in a different thread in subroutine RUN_W2.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
943 Views
OnExecute is your RUN_W2 -- however, you canDlgSetSub onthe id of the dialog itself; in that case, the callback is invoked immediately after DlgModal, which is in effect the same as if someone pressed button RUN:
IF (TRIM(sArg) = "/batch") THEN
RESULT = DLGSETSUB (DLG,OUTPUT_DIALOG, RUN_W2)
END IF
Then, add appropriate IF/CASE statement within RUN_W2 so that execution starts either
if (ID.EQ.RUN .or. (ID.EQ.OUTPUT_DIALOG .AND. CallbackType.EQ.DLG_INIT))
Jugoslav
0 Kudos
tmcole
Beginner
943 Views
The DLGSETSUB (DLG,OUTPUT_DIALOG,RUN_W2) did it and now makes sense. The other didn't and gave me error messages. Thanks. You are a scholar and a gentleman.
0 Kudos
Reply