Rikard
08-12-2005, 02:54 AM
Hi im trying to make a function that shall compare 3 numbers and return the smalest first and so on.
i tried to compare 3 numbers in a row but i guess that dont work.
Here is how i have done it:
--Enter global declarations and functions here...
-- sortera tal stigande or in english sort tal(numbers).
function sortera(tal1, tal2, tal3)
if tal1 <= tal2 <= tal3 then
return tal1, tal2, tal3
elseif tal3 <= tal1 <= tal2 then
return tal3, tal1, tal2
elseif tal2 <= tal3 <= tal1 then
return tal2, tal3, tal1
elseif tal2 <= tal1 <= tal3 then
return tal2, tal1, tal3
elseif tal3 <= tal2 <= tal1 then
return tal3, tal2, tal1
elseif tal1 <= tal3 <= tal2 then
return tal1, tal3, tal2
end
end
And on a button i call the funktion
code code code
min, med, max = sortera(solidp1, solidp2, solidp3);
if (min + 0.2) > max then
Dialog.Message("Fel", "Det är för stor skilnad mellan proven. Skilnaden mellan 2 prov får inte vara mer än 0,2. ", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
end
code code code
i tried to compare 3 numbers in a row but i guess that dont work.
Here is how i have done it:
--Enter global declarations and functions here...
-- sortera tal stigande or in english sort tal(numbers).
function sortera(tal1, tal2, tal3)
if tal1 <= tal2 <= tal3 then
return tal1, tal2, tal3
elseif tal3 <= tal1 <= tal2 then
return tal3, tal1, tal2
elseif tal2 <= tal3 <= tal1 then
return tal2, tal3, tal1
elseif tal2 <= tal1 <= tal3 then
return tal2, tal1, tal3
elseif tal3 <= tal2 <= tal1 then
return tal3, tal2, tal1
elseif tal1 <= tal3 <= tal2 then
return tal1, tal3, tal2
end
end
And on a button i call the funktion
code code code
min, med, max = sortera(solidp1, solidp2, solidp3);
if (min + 0.2) > max then
Dialog.Message("Fel", "Det är för stor skilnad mellan proven. Skilnaden mellan 2 prov får inte vara mer än 0,2. ", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
end
code code code