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