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

Issues with dialogue box (errors in box input and button commands)

belmont
Novice
1,648 Views

Hi all,

I have issues with dialogue boxes I have created in the Quick Win framework. Please look for example the dialogue box below.

 1.jpg

What I do here is potting a pointer in a plot I have created to zoom in a section of it. However I have two issues.

 

Firstly for some reason I cannot get the "Cancel" button to work. Both "OK" and "Cancel" work as "OK".  This means that any number written in the Edit Box is kept as a variable. For example I have tried (ID is IDCANCEL) 

LOGICAL bret
...
bret = DlgSetSub( dlg, IDCANCEL, cancel2)
...

with cancel2 being a simple subroutine:

subroutine cancel2()
implicit none
write(*,*) "No zoom performed"
end subroutine cancel2

or a subroutine containing cases from the above or other boxes with 

select case(local_id) 
case(IDCANCEL)
write(*,*) "No zoom performed"
end select

Nothing works. I would like to note that the X in the upper right has the same problem.

 

Secondly, if I try to input a negative number in the Edit Box the program crashes:

2.jpg

Is there a way to correct this?

 

I would like to thank everyone who answers in advance.

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
1,602 Views

Thanks for the example. Lots of issues here.

  • DLG_SELCHANGE isn't for use on edit boxes. If you wanted to be notified on ANY change to the box, use DLG_CHANGE, but you don't want that either. Instead, you want to wait until the user click OK and then get the values using DLGGET. You might use DLG_CHANGE if you wanted to validate values as they were entered, but you can't do that with list-directed input as it will fail with partial input.
  • And that means you don't want to call Update - either as an action when the control changes nor explicitly in the code.
  • If you set a callback for the Cancel button, that overrides the default actions. You don't want to do that. Leave it at the default and check for DLGMODAL returning IDCANCEL.
  • If you do call DLGSETSUB and specify a procedure (which you don't need here), you have to filter on the callback type being DLG_INIT for initialization. Also you had too many SELECT CASEs, I merged them.
  • In a QuickWin application, you really should call SLEEPQQ(500) in the spinwait loop.

Basically, the only reason to use DLGSETSUB is if you want to change the content of a dialog while the user is selecting controls. Otherwise, wait until DLGMODAL returns, and if the control return isn't IDCANCEL, get the values and process them.

A revised version is attached - some lines commented out, some removed.

View solution in original post

7 Replies
Steve_Lionel
Honored Contributor III
1,628 Views

You haven't included any of the relevant parts of the program, so it is difficult to help you. It's always best to attach a minimal but complete test case that demonstrates the problem.

Regarding Cancel, your call to DLGMODAL will return IDCANCEL. What your program does with it then is up to you.

As for the input, you have not shown us the text that is triggering the error nor the READ statement. List-directed input is very forgiving, but I'm guessing that it is being presented with something other than what you think it should.

0 Kudos
belmont
Novice
1,621 Views

Thanks for your input.

I have created a sample functioning project that shows my issue. If the code is compiled the function I have added is the last one in the "File" menu called "Input Pointer".

In the Edit Control there the user is asked to input two values to be used in numerical applications but in this example they are simply printed in the screen. If one inputs a negative "-" sign (located in the right of Zero in a typical EU keyboard) the program crashes. It also crashes if the default input is deleted without giving time to input a new value.

Finally the "Cancel" and "X" buttons show not right behaviour but this is a mistake on my part that I don't know how to fix. I have this problem also in child windows not shown in this test code.

 

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,603 Views

Thanks for the example. Lots of issues here.

  • DLG_SELCHANGE isn't for use on edit boxes. If you wanted to be notified on ANY change to the box, use DLG_CHANGE, but you don't want that either. Instead, you want to wait until the user click OK and then get the values using DLGGET. You might use DLG_CHANGE if you wanted to validate values as they were entered, but you can't do that with list-directed input as it will fail with partial input.
  • And that means you don't want to call Update - either as an action when the control changes nor explicitly in the code.
  • If you set a callback for the Cancel button, that overrides the default actions. You don't want to do that. Leave it at the default and check for DLGMODAL returning IDCANCEL.
  • If you do call DLGSETSUB and specify a procedure (which you don't need here), you have to filter on the callback type being DLG_INIT for initialization. Also you had too many SELECT CASEs, I merged them.
  • In a QuickWin application, you really should call SLEEPQQ(500) in the spinwait loop.

Basically, the only reason to use DLGSETSUB is if you want to change the content of a dialog while the user is selecting controls. Otherwise, wait until DLGMODAL returns, and if the control return isn't IDCANCEL, get the values and process them.

A revised version is attached - some lines commented out, some removed.

belmont
Novice
1,597 Views

Thank you very much for the help. The book I was reading overcomplicated things and since till now I used Combo Boxes I thought they were needed in Edit Boxes too.

One final question: DLGGET can be used generally between DLGMODAL and DLGUNINIT to update the values of the variables thus making (in simple cases as mine though) the program simpler?

0 Kudos
andrew_4619
Honored Contributor III
1,570 Views

"DLGGET can be used generally between DLGMODAL and DLGUNINIT" Yes is the answer to that! One additional comment you could have a custom exit button with a callback that  gets and checks the input and then either gives some error messages and stays in the dialog or calls dlgexit. It depends how you want to handle error conditions.

belmont_gr
Novice
1,558 Views
0 Kudos
belmont
Novice
1,521 Views

Thanks for this!

Using DLGGET between DLGMODAL and DLGUNINIT helps clarity since my code is a simple GUI running numerics. DLGSETSUB is preferably used in Combo Boxes it seems.

0 Kudos
Reply