Post Reply 
REPEAT INPUT UNTIL...
03-20-2015, 11:30 AM
Post: #1
REPEAT INPUT UNTIL...
In my program I've this code:

Code:

control:=1;
REPEAT
INPUT({a, n, s, si}, "Chi-square Variance test", {"Signif. level α=", "Sample size n=", "Sample var s²=", "Popul. var σ₀²="}, 
{"Significance level α (default 0.05)", "Sample size", "Observed Sample Variance  s²", "Population Variation σ₀²"},{0.01, 2, 1, 1}, {0.05,2,  1, 1});
CASE
IF (a <=0 OR a>= 1) THEN MSGBOX("Significance level must be > 0 AND <1"); control:=1; END;
IF (n<2) THEN MSGBOX("Sample numerosity must be >=2"); control:=1; END;
IF (s<0) THEN MSGBOX("Sample Variance must be >= 0"); control:=1; END;
IF (si<=0) THEN MSGBOX("Population Variance must be > 0"); control:=1; END;
DEFAULT control:= 0;
END; // case
UNTIL control < 1;

It works but non as I would like...
If there is an error, MSGBOX is showed after the whole input routine, then restart the input and this reset all variables...

There is a way to present every msgbox contextually to the error catching and then not to reset the variables without errors?

Thank you in advance

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-20-2015, 12:06 PM (This post was last modified: 03-20-2015 12:12 PM by Didier Lachieze.)
Post: #2
RE: REPEAT INPUT UNTIL...
(03-20-2015 11:30 AM)salvomic Wrote:  There is a way to present every msgbox contextually to the error catching and then not to reset the variables without errors?
You can set the input variables default values outside of the REPEAT ... UNTIL loop and reset only the ones that have the wrong values in the IF THEN statements:

Code:
control:=1;
a:=0.05;
n:=2;
s:=1;
si:=1;
REPEAT
INPUT({a, n, s, si}, "Chi-square Variance test", {"Signif. level α=", "Sample size n=", "Sample var s²=", "Popul. var σ₀²="}, 
{"Significance level α (default 0.05)", "Sample size", "Observed Sample Variance  s²", "Population Variation σ₀²"},{0.01, 2, 1, 1}, {a,n,s,si});
CASE
IF (a <=0 OR a>= 1) THEN MSGBOX("Significance level must be > 0 AND <1"); control:=1; a:=0.05; END;
IF (n<2) THEN MSGBOX("Sample numerosity must be >=2"); control:=1; n:=2; END;
IF (s<0) THEN MSGBOX("Sample Variance must be >= 0"); control:=1; s:=1; END;
IF (si<=0) THEN MSGBOX("Population Variance must be > 0"); control:=1; si:=1; END;
DEFAULT control:= 0;
END; // case
UNTIL control < 1;

This doesn't help to show the error message contextually when the value in entered but it avoids resetting all values to the default.
Find all posts by this user
Quote this message in a reply
03-20-2015, 12:18 PM
Post: #3
RE: REPEAT INPUT UNTIL...
(03-20-2015 12:06 PM)Didier Lachieze Wrote:  This doesn't help to show the error message contextually when the value in entered but it avoids resetting all values to the default.

thanks a lot, Didier!
So it works better, also if the errors are not contextual...

my version, after your...
Code:

EXPORT chi2_variance()
BEGIN
local a:=0.05 ,n:=2,  s:=1, si:=1, XT, chi, p;
...
local control:=1;
REPEAT
INPUT({a, n, s, si}, "Chi-square Variance test", {"Signif. level α=", "Sample size n=", "Sample var s²=", "Popul. var σ₀²="}, 
{"Significance level α (default 0.05)", "Sample size", "Observed Sample Variance  s²", "Population Variation σ₀²"},{0.01, 2, 1, 1}, {a, n,  s, si});
CASE
IF (a <=0 OR a>= 1) THEN MSGBOX("Significance level must be > 0 AND <1"); control:=1; a:=0.05; END;
IF (n<2) THEN MSGBOX("Sample numerosity must be >=2"); control:=1; n:=2; END;
IF (s<0) THEN MSGBOX("Sample Variance must be >= 0"); control:=1; s:=1; END;
IF (si<=0) THEN MSGBOX("Population Variance must be > 0"); control:=1; si:=1; END;
DEFAULT control:= 0;
END; // case
UNTIL control < 1;

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)