Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!d34g2000vbm.googlegroups.com!not-for-mail
From: Praetorian <ashish.sadanandan@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Simulink Mask Parameter Range Checking
Date: Wed, 21 Oct 2009 12:55:48 -0700 (PDT)
Organization: http://groups.google.com
Lines: 43
Message-ID: <ae9f390d-f976-4af2-b8f8-64ea7d7b485b@d34g2000vbm.googlegroups.com>
References: <hbnkrl$31a$1@fred.mathworks.com>
NNTP-Posting-Host: 63.238.229.186
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1256154948 32725 127.0.0.1 (21 Oct 2009 19:55:48 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 21 Oct 2009 19:55:48 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d34g2000vbm.googlegroups.com; posting-host=63.238.229.186; 
	posting-account=uxNuEQoAAABwxsrGxAKeLxAj2hdO1tck
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) 
	Gecko/20090824 Firefox/3.5.3,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:579092


On Oct 21, 12:45 pm, "Richard " <richard.schwa...@craneaerospace.com>
wrote:
> I am new to dealing with callback functions, and had a question about range checking, and throwing an error.
>
> I have a masked subsystem with two parameters that I would like to range check.  I want to ensure that the value entered is a positive integer.  I currently have the following initialization command callback function that runs whenever the block is initialized.  Both parameters have the Evaluate box checked in the Dialog parameters field of the Mask Editor, which as far as I can tell returns null if a string that is not a valid variable name is entered instead of a number or variable.  Is this true?
>
> function range_check(varName, errMsgName)      
>     %check that varName is not empty (meaning a string was entered),
>     %is an integer, and is positive
>     if (isempty(varName) || ...
>         rem(varName, 1) ~= 0 || ...
>        (rem(varName, 1) == 0 && varName < 1))
>         errordlg(['Number of ' errMsgName ' must be a ' ...
>                  'positive integer.'], ...
>                  'Error: Function Block Parameters');
>     end %if
> end %function
>
> This gives me an error if I click OK or APPLY (as desired), but the value still accepted, and if I click OK after the error has displayed, the Function Block Parameter box disappears, and the invalid parameter value is stored.  What is the best way to display an error message and not store the invalid value?
>
> Thanks,
>
> Richard

The way I've dealt with this in the past is to have a hidden edit box
which holds the last valid entry. If the current entry is invalid then
you load the contents of this hidden edit box into the visible one and
display the error, all within your callback function. Maybe
(hopefully) someone has a better solution.

HTH,
Ashish.