Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 4 of 4

Thread: sort 3 numbers

  1. #1
    Join Date
    May 2005
    Location
    Sweden
    Posts
    21

    sort 3 numbers

    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

  2. #2
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Hi. Well there's a couple different approaches to this task. First of all, your approach. I believe if you add a few "and" conditions that your script might work, i.e.:
    Code:
    function sortera(tal1, tal2, tal3)
    if tal1 <= tal2 and tal2 <= tal3 then
    return tal1, tal2, tal3
    elseif tal3 <= tal1 and tal1 <= tal2 then
    return tal3, tal1, tal2
    elseif tal2 <= tal3 and tal3 <= tal1 then
    return tal2, tal3, tal1
    elseif tal2 <= tal1 and tal1 <= tal3 then
    return tal2, tal1, tal3
    elseif tal3 <= tal2 and tal2 <= tal1 then
    return tal3, tal2, tal1
    elseif tal1 <= tal3 and tal3 <= tal2 then
    return tal1, tal3, tal2
    end
    end
    Now for what might be an easier approach, to insert the numbers into an array and then simply sort the array, i.e.:

    Code:
    function sortera(tal1, tal2, tal3)
    myTable={tal1,tal2,tal3};
    Table.Sort(myTable, nil);
    return myTable[1], myTable[2], myTable[3]
    end
    The second method is probably easier to extend. Hope that helps.

  3. #3
    Join Date
    May 2005
    Location
    Sweden
    Posts
    21
    Thanks Corey

  4. #4
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    No problem.

Similar Threads

  1. Serial Numbers for your AutoPlay applications
    By Desmond in forum AutoPlay Media Studio 5.0 Examples
    Replies: 12
    Last Post: 11-30-2005, 01:20 PM
  2. Help with GUID numbers
    By DarrellBlack in forum Setup Factory 7.0
    Replies: 2
    Last Post: 02-21-2005, 07:29 PM
  3. Find most used numbers - tips on easiest method please
    By Derek in forum AutoPlay Media Studio 5.0
    Replies: 9
    Last Post: 01-07-2005, 03:47 PM
  4. Sort order - International characters
    By csd214 in forum AutoPlay Media Studio 5.0
    Replies: 0
    Last Post: 03-24-2004, 10:53 AM
  5. I can't create Serials Numbers
    By adriancas in forum Setup Factory 6.0
    Replies: 2
    Last Post: 12-17-2003, 10:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts