New topic: MsgBox Question
<http://forums.realsoftware.com/viewtopic.php?t=30492> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message martinpaulrice Post subject: MsgBox QuestionPosted: Thu Oct 15, 2009 9:33 am Joined: Wed Apr 11, 2007 1:17 pm Posts: 130 Location: Signal Mountain, TN In the LR, in an example for putting up a MsgBox with Yes and No the code is as follows: Code:Dim n as Integer n=MsgBox("Do you want to rebuild this mailbox",36) If n=6 then //user pressed Yes elseif n=7 then //user pressed No end if I put this in my app a couple of months ago and today, while going over my code carefully, I noticed what seems to be an anomaly here. the buttons are 36, No, Yes, but the elseif says if n = 7. There is no 7. Then, looking at the LR again, I noticed that 2 is cancel, 3 is abort, 7 is no. So I have two questions about this: What's the difference between cancel, abort, and no? And will the code above from the LR work correctly? That then led me to another question. I put this in where it says //user pressed No: Code:else if n = 7 then //user pressed No MakeStuffInactiveTrans pbTransNew.Enabled = True exit end if end if Do I want "exit" or "return?" I just remembered that I once read, or thought I did, that exit is used to break out of a loop. But if I want to get out of the event, should I use return? Well, that leads me to one more question: What happens if I use 2 or 3, cancel or abort. Would either of those take me out of the event without having to use exit or return, or would I have to use one of those in any case? Thanks. _________________ Martin Signal Mountain, TN Top Mike Bailey Post subject: Re: MsgBox QuestionPosted: Thu Oct 15, 2009 9:52 am Joined: Wed Sep 28, 2005 8:30 am Posts: 5435 Location: Austin, TX The buttons are only going to do what you tell them to do. When you tell the MsgBox function to display Cancel and Abort buttons, you still need to get the result from the function, which will tell you which button the user pressed, and then determine what to do from there. I prefer to just use the return keyword to stop execution of a method, but you can use the exit keyword if you specify that you want to leave the method. This is done by doing either exit sub or exit function, depending on where you are. Return works on all code containers (events, methods, functions, etc) with the same syntax. You might also look into using the MessageDialog class instead of MsgBox. It will give you a lot more control over the display and the code is a lot easier to read without having to rely on magic numbers to determine what button choices there are. Hope this helps. _________________ Mike Bailey Ekim Software http://www.ekimsoftware.com/ Top martinpaulrice Post subject: Re: MsgBox QuestionPosted: Thu Oct 15, 2009 10:11 am Joined: Wed Apr 11, 2007 1:17 pm Posts: 130 Location: Signal Mountain, TN Thanks, Mike. That did indeed help and I'll check out the Message Dialog class right now. I appreciate your answer. _________________ Martin Signal Mountain, TN Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
