Page 1 of 1

Writing (multiple) output to edit control

Posted: 3 Dec 2016 15:34
by theayanamirin
Hello!
So, I am writing a bus schedule app.
I have this form where you have to tell departure point, destination point and a day and when you click on "Resluts" button, it should return all buses numbers and time of their departure and write it to the Results edit control.

so i have a predicate (private)

Code: Select all

route:(string DepCity, string DestCity, day Day, stops Stops)nondeterm anyflow.
...

Code: Select all

route(P1,P2,Day,[stop(Number,P1,P2,DepTime)]):-                              tripschedule(P1,P2,Number,DepTime,_,Day).   route(P1,P2,Day,[stop(Number,P1,P15, DepTimeP1)|Route]):-                              tripschedule(P1,P15,Number,DepTimeP1,ArrTimeP15,Day),                              route(P15, P2, Day, Route),                              setdeparturetime(Route,DepTimeP2),                              transfer(ArrTimeP15,DepTimeP2).
stops list is

Code: Select all

stop = stop(integer TripNum, string DepCity, string DestCity, time TimeOfTr). stops = stop*.
and time type is

Code: Select all

 time = time(integer Hour, integer Minutes)
and an event handler

Code: Select all

onResButtonClick(_Source) = button::defaultAction():-                                                 P1=src_ctl:getText(),                                                 P2 = dir_ctl:getText(),                                                 Day = wkday_ctl:getText(),                                                 sp::resultpredicate(P1,P2,Day,Output), %idk how to write this predicate                                                 res_ctl:setText(Output).
So i have to write this resultpredicate which must return multiple lines if route predicate returns true or "No buses" if predicate returns false, and write it to the last edit control.


It was easier to do in the console mode using fail, but I have no idea how to do it with GUI. Is it even possible?

Posted: 3 Dec 2016 21:10
by Harrison Pratt
Your code indicates you have good comprehension of VIP so I'll just make a general suggestion:
  • Make a non-deterministic predicate which returns Output (a string showing the desired information) given input of P1,P2 and Day.

    Use list comprehension to collect all the matching Outputs as a Output_List (the lines to display).

    Use string::concatWithDelimiter( Output_List , "\n" ) to create a string you can display with res_ctl:setText/1.

Posted: 4 Dec 2016 0:59
by Thomas Linder Puls
If you have a "console" routine that can write the result, then you can pass a string stream to that predicate and obtain the result and put it into the text control:
The sp::resultpredicate will take an outputStream as first argument and write the result to that stream.

The code above can be condensed to this:

Posted: 4 Dec 2016 23:13
by Harrison Pratt
Thomas, thanks for the reminder about using streams! That approach is much easier than creating and managing my own predicate-specific binary buffers. :D

Posted: 5 Dec 2016 19:00
by theayanamirin
Thomas, thank you so much!! Worked brilliantly!