Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: GUI, evaluate 'return' in caller

Subject: GUI, evaluate 'return' in caller

From: jay vaughan

Date: 17 Apr, 2008 19:00:16

Message: 1 of 2

Hi,

I am working on a GUI. For it, I wrote a subroutine (stored
in a different .m file from the GUI) that checks the user's
answers to various dialog boxes such as listdlg or inputdlg
to see that the answers are valid before continuing. In the
case of an invalid answer the code should just evaluate the
command 'return' and not continue on with the bad answer.

Most of the code works as planned but I can't get the error
checking subroutine to actually evaluate the command
'return' in the calling function. I was trying to do this
by using the following code in the error checker, but it
doesn't seem to work. Any ideas what I am doing wrong?

if valid_answer==0
   msgbox('invalid answer')
   cmd = 'return';
   evalin('caller',cmd);
end


An alternative I considered was to have the error checker
return a variable indicating whether there is an error, and
then using an if statement within the GUI function as shown
below. This would also get the job done, but I hoped to not
have to repeat this code 20 times in my program for all the
places where there are user inputs.

valid_answer = errorchecker(answer,valid_answers);
if valid_answer==0
   msgbox('invalid answer')
   return
end

In case it makes a difference, I am using version 7.1.0.246.

Thanks,
J


Subject: Re: GUI, evaluate 'return' in caller

From: helper

Date: 17 Apr, 2008 20:05:05

Message: 2 of 2

"jay vaughan" <jvaughan5.nospam@gmail.com> wrote in message
<fu86o0$phi$1@fred.mathworks.com>...
> Hi,
>
> I am working on a GUI. For it, I wrote a subroutine
(stored
> in a different .m file from the GUI) that checks the
user's
> answers to various dialog boxes such as listdlg or
inputdlg
> to see that the answers are valid before continuing. In
the
> case of an invalid answer the code should just evaluate
the
> command 'return' and not continue on with the bad answer.
>
> Most of the code works as planned but I can't get the
error
> checking subroutine to actually evaluate the command
> 'return' in the calling function. I was trying to do this
> by using the following code in the error checker, but it
> doesn't seem to work. Any ideas what I am doing wrong?
>
> if valid_answer==0
> msgbox('invalid answer')
> cmd = 'return';
> evalin('caller',cmd);
> end
>
>
> An alternative I considered was to have the error checker
> return a variable indicating whether there is an error,
and
> then using an if statement within the GUI function as
shown
> below. This would also get the job done, but I hoped to
not
> have to repeat this code 20 times in my program for all
the
> places where there are user inputs.
>
> valid_answer = errorchecker(answer,valid_answers);
> if valid_answer==0
> msgbox('invalid answer')
> return
> end
>
> In case it makes a difference, I am using version
7.1.0.246.
>
> Thanks,
> J
>
>

Note that even "eval('return')" doesn't work. I suggest
your second option is by far the better method (eval is
evil). You can simplify it to:

if errorchecker(answer,valid_answers)
  return
end

and have ERRORCHECKER display the msgbox and return a
logical.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
eval helper 17 Apr, 2008 16:10:23
gui jay vaughan 17 Apr, 2008 15:05:06
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics