Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: GUI, evaluate 'return' in caller
Date: Thu, 17 Apr 2008 20:05:05 +0000 (UTC)
Organization: Timothy S. Farajian, Inc.
Lines: 65
Message-ID: <fu8ahh$c8i$1@fred.mathworks.com>
References: <fu86o0$phi$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1208462705 12562 172.30.248.35 (17 Apr 2008 20:05:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 17 Apr 2008 20:05:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1272923
Xref: news.mathworks.com comp.soft-sys.matlab:463712



"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.