Writing (multiple) output to edit control

Discussions related to Visual Prolog
theayanamirin
Posts: 2
Joined: 30 Nov 2016 9:59

Writing (multiple) output to edit control

Unread post by theayanamirin » 3 Dec 2016 15:34

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?
Attachments
theform.PNG
my form looks like this
theform.PNG (5.8 KiB) Viewed 2255 times

Harrison Pratt
VIP Member
Posts: 283
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt » 3 Dec 2016 21:10

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.

User avatar
Thomas Linder Puls
VIP Member
Posts: 1622
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 4 Dec 2016 0:59

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:
Regards Thomas Linder Puls
PDC

Harrison Pratt
VIP Member
Posts: 283
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt » 4 Dec 2016 23:13

Thomas, thanks for the reminder about using streams! That approach is much easier than creating and managing my own predicate-specific binary buffers. :D

theayanamirin
Posts: 2
Joined: 30 Nov 2016 9:59

Unread post by theayanamirin » 5 Dec 2016 19:00

Thomas, thank you so much!! Worked brilliantly!

Post Reply