46.2.1 Opening and Closing a Query

Prolog queries are represented in Visual Basic in textual form, i.e. as a string containing the query, but not followed by a full stop. For example, the following Visual Basic code fragments create valid Prolog queries:

     'Q1 is a query finding the first "good" element of the list [1,2,3]
     Q1 = "member(X,[1,2,3]), good(X)"
     
     'create a Q2 query finding the first "good" element of the list
     '[1,2,...,N]:
     Q2 = "member(X,["
     For i = 1 To N-1
        Q2 = Q2 & i & ","
     Next
     Q2 = Q2 & N & "]), good(X)"

Before executing a query, it has to be explicitly opened, via the PrologOpenQuery function, which will return a query identifier that can be used for successive retrieval of solutions.

The PrologCloseQuery procedure will close the query represented by a query identifier. The use of an invalid query identifier will result in undefined behavior. For example:

     Dim qid As Long
     
     Q1 = "member(X,[1,2,3]), good(X)"
     qid = PrologOpenQuery(Q1)
     
        ... <execution of the query> ...
     
     PrologCloseQuery(qid)