Path: news.mathworks.com!not-for-mail
From: "jay vaughan" <jvaughan5.nospam@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: GUI, evaluate 'return' in caller
Date: Thu, 17 Apr 2008 19:00:16 +0000 (UTC)
Organization: harvard
Lines: 41
Message-ID: <fu86o0$phi$1@fred.mathworks.com>
Reply-To: "jay vaughan" <jvaughan5.nospam@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1208458816 26162 172.30.248.37 (17 Apr 2008 19:00:16 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 17 Apr 2008 19:00:16 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1215048
Xref: news.mathworks.com comp.soft-sys.matlab:463703



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