<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167793</link>
    <title>MATLAB Central Newsreader - GUI, evaluate 'return' in caller</title>
    <description>Feed for thread: GUI, evaluate 'return' in caller</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 17 Apr 2008 19:00:16 -0400</pubDate>
      <title>GUI, evaluate 'return' in caller</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167793#427361</link>
      <author>jay vaughan</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I am working on a GUI. For it, I wrote a subroutine (stored &lt;br&gt;
in a different .m file from the GUI) that checks the user's &lt;br&gt;
answers to various dialog boxes such as listdlg or inputdlg &lt;br&gt;
to see that the answers are valid before continuing. In the &lt;br&gt;
case of an invalid answer the code should just evaluate the &lt;br&gt;
command 'return' and not continue on with the bad answer.&lt;br&gt;
&lt;br&gt;
Most of the code works as planned but I can't get the error &lt;br&gt;
checking subroutine to actually evaluate the command &lt;br&gt;
'return' in the calling function. I was trying to do this &lt;br&gt;
by using the following code in the error checker, but it &lt;br&gt;
doesn't seem to work. Any ideas what I am doing wrong?&lt;br&gt;
&lt;br&gt;
if valid_answer==0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;msgbox('invalid answer')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;cmd = 'return';&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;evalin('caller',cmd);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
An alternative I considered was to have the error checker &lt;br&gt;
return a variable indicating whether there is an error, and &lt;br&gt;
then using an if statement within the GUI function as shown &lt;br&gt;
below. This would also get the job done, but I hoped to not &lt;br&gt;
have to repeat this code 20 times in my program for all the &lt;br&gt;
places where there are user inputs.&lt;br&gt;
&lt;br&gt;
valid_answer = errorchecker(answer,valid_answers);&lt;br&gt;
if valid_answer==0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;msgbox('invalid answer')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
In case it makes a difference, I am using version 7.1.0.246.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
J&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 17 Apr 2008 20:05:05 -0400</pubDate>
      <title>Re: GUI, evaluate 'return' in caller</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167793#427370</link>
      <author>helper </author>
      <description>"jay vaughan" &amp;lt;jvaughan5.nospam@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fu86o0$phi$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am working on a GUI. For it, I wrote a subroutine &lt;br&gt;
(stored &lt;br&gt;
&amp;gt; in a different .m file from the GUI) that checks the &lt;br&gt;
user's &lt;br&gt;
&amp;gt; answers to various dialog boxes such as listdlg or &lt;br&gt;
inputdlg &lt;br&gt;
&amp;gt; to see that the answers are valid before continuing. In &lt;br&gt;
the &lt;br&gt;
&amp;gt; case of an invalid answer the code should just evaluate &lt;br&gt;
the &lt;br&gt;
&amp;gt; command 'return' and not continue on with the bad answer.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Most of the code works as planned but I can't get the &lt;br&gt;
error &lt;br&gt;
&amp;gt; checking subroutine to actually evaluate the command &lt;br&gt;
&amp;gt; 'return' in the calling function. I was trying to do this &lt;br&gt;
&amp;gt; by using the following code in the error checker, but it &lt;br&gt;
&amp;gt; doesn't seem to work. Any ideas what I am doing wrong?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; if valid_answer==0&lt;br&gt;
&amp;gt;    msgbox('invalid answer')&lt;br&gt;
&amp;gt;    cmd = 'return';&lt;br&gt;
&amp;gt;    evalin('caller',cmd);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; An alternative I considered was to have the error checker &lt;br&gt;
&amp;gt; return a variable indicating whether there is an error, &lt;br&gt;
and &lt;br&gt;
&amp;gt; then using an if statement within the GUI function as &lt;br&gt;
shown &lt;br&gt;
&amp;gt; below. This would also get the job done, but I hoped to &lt;br&gt;
not &lt;br&gt;
&amp;gt; have to repeat this code 20 times in my program for all &lt;br&gt;
the &lt;br&gt;
&amp;gt; places where there are user inputs.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; valid_answer = errorchecker(answer,valid_answers);&lt;br&gt;
&amp;gt; if valid_answer==0&lt;br&gt;
&amp;gt;    msgbox('invalid answer')&lt;br&gt;
&amp;gt;    return&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; In case it makes a difference, I am using version &lt;br&gt;
7.1.0.246.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; J&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Note that even "eval('return')" doesn't work.  I suggest &lt;br&gt;
your second option is by far the better method (eval is &lt;br&gt;
evil).  You can simplify it to:&lt;br&gt;
&lt;br&gt;
if errorchecker(answer,valid_answers)&lt;br&gt;
&amp;nbsp;&amp;nbsp;return&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
and have ERRORCHECKER display the msgbox and return a &lt;br&gt;
logical.&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
