Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OK and ESC

65 views
Skip to first unread message

PeCoNe

unread,
Mar 6, 2013, 11:05:51 AM3/6/13
to
Hallo,

I wrote a program with an input dialog box as follows:

iDlg = .inputbox~new("Specify Search Criteria (xxx[,zzz...])", -
"File Maintenance Utility","",200)

ss = iDlg~execute
ss is the value entered.

I searched the manual how to test the OK or ESC key but i could not find
it, so how can i test if user pressed OK or ESC

Thanks Peter.

Mark Miesfeld

unread,
Mar 6, 2013, 10:16:46 PM3/6/13
to
If the user pressed the Ok button, then ss will be the text in the
edit control. If the user presses the Cancel button, the Esc key, or
closes the dialog in any other way than using the Ok button, ss will
be the empty string.

--
Mark Miesfeld

Bob Martin

unread,
Mar 7, 2013, 2:28:35 AM3/7/13
to
in 54932 20130307 031646 Mark Miesfeld <mies...@gmail.com> wrote:
>On Mar 6, 8:05=A0am, PeCoNe <malj...@telfort.nl> wrote:
>> I wrote a program with an input dialog box as follows:
>>
>> =A0 =A0 =A0iDlg =3D .inputbox~new("Specify Search Criteria (xxx[,zzz...])=
>", -
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "File Maintenance Uti=
>lity","",200)
>>
>> =A0 =A0 =A0ss =3D iDlg~execute
>> =A0 =A0 =A0ss is the value entered.
>>
>> I searched the manual how to test the OK or ESC key but i could not find
>> it, so how can i test if user pressed OK or ESC
>
>If the user pressed the Ok button, then ss will be the text in the
>edit control. If the user presses the Cancel button, the Esc key, or
>closes the dialog in any other way than using the Ok button, ss will
>be the empty string.

What if the user presses OK with the edit control empty - ie because he
wants to enter an empty string?

PeCoNe

unread,
Mar 7, 2013, 9:35:24 AM3/7/13
to
Op 2013-03-07 04:16, Mark Miesfeld schreef:
thanks for the answer.
I had planned to use OK with no input for adding a new record,
so i must look for another option.

Bye Peter Maljers

Mark Miesfeld

unread,
Mar 7, 2013, 10:23:41 AM3/7/13
to
On Mar 7, 6:35 am, PeCoNe <malj...@telfort.nl> wrote:

> thanks for the answer.
> I had planned to use OK with no input for adding a new record,
> so i must look for another option.

Rather than change your design, you should just use a dialog that does
what you want. The standard dialogs are very simplistic and not
flexible. The whole purpose of ooDialog is to allow you to create any
dialog you need.

This program catches OK with no input allowing you to add a new
record:

/* catchOk.rx */

dlg = .CatchOkDialog~new
dlg~execute("SHOWTOP", IDI_DLG_OOREXX)

::requires "ooDialog.cls"

::class 'CatchOkDialog' subclass UserDialog

::method init
forward class (super) continue

self~create(30, 30, 275, 66, "Data Entry Dialog", "CENTER")

::method defineDialog

msg = 'Enter some data. Press Ok with no ' || -
'text entered to start a new record'

self~createStaticText(IDC_STATIC, 10, 10, 255, 8, , msg)
self~createEdit(200, 10, 21, 255, 11, 'AUTOSCROLLH')
self~createPushButton(IDOK, 160, 42, 50, 14, "DEFAULT", "Ok")
self~createPushButton(IDCANCEL, 215, 42, 50, 14, , "Cancel")

::method ok unguarded

text = self~newEdit(200)~getText~strip
if text == '' then do
title = 'New Record'
msg = 'The user requested a new record'
end
else do
title = 'Data Entered'
msg = 'Data:' text
end
j = MessageDialog(msg, self~hwnd, title, 'OK')

return self~ok:super

::method cancel unguarded

title = 'Data Entry Canceled'
msg = 'The user canceled the dialog'
j = MessageDialog(msg, self~hwnd, title, 'OK')

return self~cancel:super

/* End catchOk.rx */


--
Mark Miesfeld

Mark Miesfeld

unread,
Mar 7, 2013, 10:32:52 AM3/7/13
to
On Mar 6, 11:28 pm, Bob Martin <bob.mar...@excite.com> wrote:

> What if the user presses OK with the edit control empty - ie because he
> wants to enter an empty string?

Then you would get back the empty string. If you need to be able to
distinguish what the user wanted, then the InputDialog is the wrong
tool for the job.

The standard dialogs supplied by ooDialog, of which InputDialog is
one, are very simplistic and inflexible. Personally I think they are
a waste of time and would never use them.

Normally you would design your application and then design a dialog
that presents to the user exactly what you want. A one size fits all
approach here does not work well.

--
Mark Miesfeld

Glenn Knickerbocker

unread,
Mar 7, 2013, 12:30:36 PM3/7/13
to
On 3/6/2013 11:05 AM, PeCoNe wrote:
> I searched the manual how to test the OK or ESC key but i could not find
> it, so how can i test if user pressed OK or ESC

Hmmm. The doc says that InputBox is a subclass of the PlainUserDialog
class, and that the Finished attribute of PlainUserDialog returns:

> 0 if dialog is executing, 1 if terminated with OK, and 2 if canceled

I can't get it ever to return 2, though. Whether I press OK or Cancel
or just close the window, it always returns 1. What am I missing?

ŹR

Glenn Knickerbocker

unread,
Mar 7, 2013, 12:52:53 PM3/7/13
to
On 3/7/2013 12:30 PM, I wrote:
> Hmmm. The doc says that InputBox is a subclass of the PlainUserDialog
> class, and that the Finished attribute of PlainUserDialog returns:
> > 0 if dialog is executing, 1 if terminated with OK, and 2 if canceled

Aha, looks like that was accidentally copied from the next attribute in
the list:

> InitCode
...
> After the dialog is finished, the attribute will be 1 if the user
> terminated the dialog with the Ok button. Its value will be 2 if the
> user canceled the dialog.

So just check the value of iDlg~InitCode after you get your input:

ss = iDlg~execute
Select
When iDlg~InitCode = 2 then /* user canceled */
When iDlg~InitCode = 0 then /* this should never happen */
When ss = '' then /* create a new record */
Otherwise /* use the entered value of SS */
End

�R

PeCoNe

unread,
Mar 7, 2013, 2:07:38 PM3/7/13
to Glenn Knickerbocker
Op 2013-03-07 18:52, Glenn Knickerbocker schreef:
> ss = iDlg~execute
> Select
> When iDlg~InitCode = 2 then /* user canceled */
> When iDlg~InitCode = 0 then /* this should never happen */
> When ss = '' then /* create a new record */
> Otherwise /* use the entered value of SS */
> End

Thanks Glenn.
This is what i was looking for.
Coded in my program and now it works fine.

Bye Peter Maljers

sebv...@gmail.com

unread,
Aug 24, 2016, 2:26:27 PM8/24/16
to
I was looking this for quite sometimes now. You made my day ! Thanks.

LesK

unread,
Aug 25, 2016, 12:11:27 AM8/25/16
to
On 8/24/2016 2:26 PM, sebv...@gmail.com wrote:
> I was looking this for quite sometimes now. You made my day ! Thanks.
>
I don't see your original question and the answer that you are so happy
about. Are you sure you're posting to the right place?

It's always nice to Post Below for Newsgroups and include what you're
posting about.

--

Les (Change Arabic to Roman to email me)

0 new messages