FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


Writing (multiple) output to edit control

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog
View previous topic :: View next topic  
Author Message
theayanamirin




Joined: 30 Nov 2016
Posts: 2

PostPosted: 3 Dec 2016 15:34    Post subject: Writing (multiple) output to edit control Reply with quote

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)

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

...


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

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

and time type is

 time = time(integer Hour, integer Minutes)

and an event handler


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?



theform.PNG
 Description:
my form looks like this
 Filesize:  5.8 KB
 Viewed:  569 Time(s)

theform.PNG


Back to top
View user's profile Send private message
Harrison Pratt



Des Moines, Iowa USA
Joined: 05 Nov 2000
Posts: 290

PostPosted: 3 Dec 2016 21:10    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3077

PostPosted: 4 Dec 2016 0:59    Post subject: Reply with quote

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:

clauses
    onResButtonClick(_Source) = button::defaultAction() :-
        P1=src_ctl:getText(),
        P2 = dir_ctl:getText(),
        Day = wkday_ctl:getText(),
        OutputStream = outputStream_string::new(),
        sp::resultpredicate(OutputStream, P1, P2, Day),
        Output = OutputStream:getString(),
        res_ctl:setText(Output).

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:

clauses
    onResButtonClick(_Source) = button::defaultAction() :-
        P1=src_ctl:getText(),
        P2 = dir_ctl:getText(),
        Day = wkday_ctl:getText(),
        Output = outputStream_string::getString(sp::resultpredicate, P1, P2, Day),
        res_ctl:setText(Output).


_________________
Regards Thomas Linder Puls
Prolog Development Center
Back to top
View user's profile Send private message
Harrison Pratt



Des Moines, Iowa USA
Joined: 05 Nov 2000
Posts: 290

PostPosted: 4 Dec 2016 23:13    Post subject: Reply with quote

Thomas, thanks for the reminder about using streams! That approach is much easier than creating and managing my own predicate-specific binary buffers. Very Happy
Back to top
View user's profile Send private message
theayanamirin




Joined: 30 Nov 2016
Posts: 2

PostPosted: 5 Dec 2016 19:00    Post subject: Reply with quote

Thomas, thank you so much!! Worked brilliantly!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum