1. Can csort.ex be rewitten to display it output in a Windows (FORM) ????
- Posted by davebee Jul 10, 2009
- 882 views
Trying to display output of csort.ex in a windows (form).
2. Re: Can csort.ex be rewitten to display it output in a Windows (FORM) ????
- Posted by DerekParnell (admin) Jul 10, 2009
- 935 views
davebee said...
Trying to display output of csort.ex in a windows (form).
-- Demo of custom_sort(), routine_id() -- The Euphoria custom_sort routine is passed the routine id -- of the comparison function to be used when sorting. include std/sort.e -- contains custom_sort() constant NAME = 1, POPULATION = 2 constant statistics = { {"Canada", 27.4}, {"United States", 255.6}, {"Brazil", 150.8}, {"Denmark", 5.2}, {"Sweden", 8.7}, {"France", 56.9}, {"Germany", 80.6}, {"Netherlands", 15.2}, {"Italy", 58.0}, {"New Zealand", 3.4} } function compare_name(sequence a, sequence b) -- Compare two sequences (records) according to NAME. return compare(a[NAME], b[NAME]) end function function compare_pop(sequence a, sequence b) -- Compare two sequences (records) according to POPULATION. -- Note: comparing b vs. a, rather than a vs. b, makes -- the bigger population come first. return compare(b[POPULATION], a[POPULATION]) end function sequence sorted_by_pop, sorted_by_name integer by_pop, by_name by_pop = routine_id("compare_pop") by_name = routine_id("compare_name") sorted_by_pop = custom_sort(by_pop, statistics) sorted_by_name = custom_sort(by_name, statistics) -- Output to a sequence first. sequence txt txt = "" txt &= "sorted by population\tsorted by name\r\n\r\n" for i = 1 to length(sorted_by_pop) do txt &= sprintf("%-13s %6.1f\t%-13s %6.1f\r\n", sorted_by_pop[i] & sorted_by_name[i]) end for -- Create window and display area. include win32lib.ew constant win = create(Window, "CSORT EXAMPLE", 0, 0, 0, 630, 630, 0) constant ow = create(MleText, txt, win, 5, 5, 590, 590, ES_READONLY) setFont(ow, "Courier New",0, 0) -- Open the window WinMain(win, Normal)