→000001TEXT("Usage of out properties in functions");
→000002TEXT("Common problem with functions is how to get result to global scope, when returned local variable");
→000013TEXT("is not between global variables and print (present) body of function - used formulas");
→000003TEXT("Three ways are generally possible");
→000004TEXT("1. Direct return");
→000005TEXT("2. Using structure which is returned");
→000006TEXT("3. Out property");
→008530TEXT("Summary");
→008531TEXT("First type is recommended for functions without visible layout output. Therefore they are used only for assign.");
→008532TEXT("Second type is recommended for functions which somehow modify already existed array or structure. It is potencially dangerous, because something is changed without any notification");
→008533TEXT("Third type is recommended for functions which are displayed in layout and which return some values to global variables.");
→000008TEXT("1. Direct return");
double Calculate_Area_first(double b, double h) {
double<m↑2←,2> A →000009= b*h;
return A;
}
b →000011= 0.5;
h →000012= 1;
→000014Calculate_Area_first(b, h);
A↓1← →000010= Calculate_Area_first(b, h);
→008522TEXT("+: Function is simple.");
→000015TEXT("-: Function have to be calculated twice. First for display second for assign. 2 rows in script");
→008534TEXT("- : The slowest, about 60 μs in this example");
→000016TEXT("2. Using structure which is returned");
void Calculate_Area_second(double b, double h) {
double<m↑2←,2> A →000017= b*h;
→008518Result.Set("A", A);
}
b →000018= 0.6;
h →000019= 1;
object Result →008520= new Structure();
→000022Calculate_Area_second(b, h);
A↓2← →000021= →008519Result.A;
→008523TEXT("+: Function is calculated just once");
→008521TEXT("-: Global object Result have to exist, 3 rows in script, potencially dangerous - modification");
→008535TEXT("- : Slow, about 30 μs in this example");
→008524TEXT("3. Out property");
void Calculate_Area_third(double b, double h, out double A) {
double<m↑2←,2> A →008525= b*h;
}
b →008526= 0.7;
h →008527= 1;
→008528Calculate_Area_third(b, h, out A↓3←);
→008529TEXT("+: Function is calculated just once, function is simple, only one row, assign is done together with calling the function");
→008536TEXT("+ : The fastest, about 18 μs in this example");
http://designforms.net
Calculation
Layout 0
Layout 1
Layout 2
Layout 3
Layout 4
Layout 5
-
"Usage of out properties in functions"
-
"Common problem with functions is how to get result to global scope, when returned local variable"
-
"Three ways are generally possible"
-
"1. Direct return"
-
"2. Using structure which is returned"
-
"3. Out property"
-
"1. Direct return"
-
"is not between global variables and print (present) body of function - used formulas"
-
"-: Function have to be calculated twice. First for display second for assign. 2 rows in script"
-
"2. Using structure which is returned"
-
"-: Global object Result have to exist, 3 rows in script, potencially dangerous - modification"
-
"+: Function is simple."
-
"+: Function is calculated just once"
-
"3. Out property"
-
"+: Function is calculated just once, function is simple, only one row, assign is done together with calling the function"
-
"Summary"
-
"First type is recommended for functions without visible layout output. Therefore they are used only for assign."
-
"Second type is recommended for functions which somehow modify already existed array or structure. It is potencially dangerous, because something is changed without any notification"
-
"Third type is recommended for functions which are displayed in layout and which return some values to global variables."
-
"- : The slowest, about 60 μs in this example"
-
"- : Slow, about 30 μs in this example"
-
"+ : The fastest, about 18 μs in this example"