Page 1 of 1

To show a message with MessageBox

Posted: 17 May 2020 23:31
by alonso
Good afternoon.
I hope someone help me.
I am working with GUI--> MessageBox

How can i show a short message on the screen, with the reply or the button you clicked as a message?
What can i do with the variable "_answer".
Thank you for reading.

predicates
onMensajesMessagebox1 : window::menuItemListener.
clauses
onMensajesMessagebox1(_Source, _MenuTag) :-
_answer = messageBox("Message Title", "This is a Message", 3, 2, 1, 0).
%What Next

Re: To show a message with MessageBox

Posted: 18 May 2020 12:22
by Harrison Pratt
The return value is the button number (1...N) you clicked. You may use it to control subsequent program flow:

Code: Select all

        ButtonNumClicked =             vpiCommonDialogs::messageBox("Message Title", "This is a Message", vpiDomains::mesbox_iconError,                 vpiDomains::mesbox_buttonsokcancel, vpiDomains::mesbox_defaultfirst,                 vpiDomains::mesbox_suspendapplication),         stdio::write("\n You clicked button "),         if ButtonNumClicked = 1 then             stdio::write("[OK]")         else             stdio::write("[Cancel]")         end if.
In this case, pressing the [Esc] key or closing the dialog by clicking the title bar [X] returns '2'. You can omit the vpiDomains:: qualification if vpiDomains is listed in the open statement of the .pro file.

It is better code style to use the mesbox_XXX constants rather than the integers so you can easy see what your intent was for the code after a month or two. :wink: