# FXMessageBox - basics

**URL:** <https://www.ruby-forum.com/t/fxmessagebox-basics/191524>\
**Category:** FXRuby\
**Created:** [July 13, 2010, 10:05pm UTC](https://www.ruby-forum.com/t/fxmessagebox-basics/191524 "2010-07-13T22:05:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [July 13, 2010, 10:05pm UTC](https://www.ruby-forum.com/t/fxmessagebox-basics/191524/1 "2010-07-13T22:05:13Z")

</div>

I am just learning Ruby/FXRuby basics and am struggling trying to  
capture the return value from an FXMessageBox. The following snippet of  
code (copied/modified from the web) causes the app to crash. The app  
generally works and clicking ‘Message Box 2’, which handler excludes  
references to ‘response’, runs without problem (though does nothing  
useful). Any clues as to what I’m doing wrong (debugging isn’t working  
for me yet, either)? Thanks for any help in advance.

David

…

msgbox\_1\_cmd = FXMenuCommand.new(msgbox\_menu, “Message Box &1”)  
msgbox\_1\_cmd.connect(SEL\_COMMAND) do  
response = FXMessageBox.new( self,  
“Message Box 1”,  
“This is Message Box 1”,  
nil,  
MBOX\_OK\_CANCEL|DECOR\_TITLE|DECOR\_BORDER)  
response.execute PLACEMENT\_OWNER

if MBOX\_CLICKED\_OK == response  
FXMessageBox.new( self,  
“Message Box 1 Result”,  
“You clikced ‘OK’”,  
nil,  
MBOX\_OK\_CANCEL|DECOR\_TITLE|DECOR\_BORDER)  
return 1  
else  
FXMessageBox.new( self,  
“Message Box 1 Result”,  
“You clikced ‘Cancel’”,  
nil, MBOX\_OK\_CANCEL|DECOR\_TITLE|DECOR\_BORDER)  
return 1  
end  
end

…

---

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [July 20, 2010, 1:09pm UTC](https://www.ruby-forum.com/t/fxmessagebox-basics/191524/2 "2010-07-20T13:09:26Z")

</div>

Hi there David,  
I use foxGUIb for my GUI stuff so take what i say as you wish.

When I played with dialog boxes I had to create a class or create an  
instance variable and make reference through that SO…

what is the value reported to be in response? could it be MBOX\_OKAY?  
and is MBOX\_OKAY equal in value to MBOX\_OK\_CLICKED?

I’ve not run you’re program at all just hoped this might help you.

dave.

David Mccrea wrote:

> I am just learning Ruby/FXRuby basics and am struggling trying to  
> capture the return value from an FXMessageBox. The following snippet of  
> code (copied/modified from the web) causes the app to crash. The app  
> generally works and clicking ‘Message Box 2’, which handler excludes  
> references to ‘response’, runs without problem (though does nothing  
> useful). Any clues as to what I’m doing wrong (debugging isn’t working  
> for me yet, either)? Thanks for any help in advance.
> 
> David
> 
> …
> 
> msgbox\_1\_cmd = FXMenuCommand.new(msgbox\_menu, “Message Box &1”)  
> msgbox\_1\_cmd.connect(SEL\_COMMAND) do  
> response = FXMessageBox.new( self,  
> “Message Box 1”,  
> “This is Message Box 1”,  
> nil,  
> MBOX\_OK\_CANCEL|DECOR\_TITLE|DECOR\_BORDER)  
> response.execute PLACEMENT\_OWNER
> 
> if MBOX\_CLICKED\_OK == response  
> FXMessageBox.new( self,  
> “Message Box 1 Result”,  
> “You clikced ‘OK’”,  
> nil,  
> MBOX\_OK\_CANCEL|DECOR\_TITLE|DECOR\_BORDER)  
> return 1  
> else  
> FXMessageBox.new( self,  
> “Message Box 1 Result”,  
> “You clikced ‘Cancel’”,  
> nil, MBOX\_OK\_CANCEL|DECOR\_TITLE|DECOR\_BORDER)  
> return 1  
> end  
> end
> 
> …
