On Aug 25, 2008, at 11:15 AM, seyed hossein wrote:
Hi,
Thanks Mr. Kirby for the response,
As I mentioned in my previous email, I've called next in my
program's deffunction running-query [(?result next)], but why does
it return false? I think the problem is caused by calling the
defquery within a deffuction. Does anyone know a better way of
connecting a Gui-text with defquery?
Thank you
Your query is returning no results because you're using "sym-cat" to
turn the String you get from a textfield in your GUI into a symbol,
then passing that symbol to run-query. But the telephone numbers in
the facts aren't symbols, they're integers. You need to use the same
data type in your query as you're using in the facts. If you used
"integer" instead of "sym-cat", your program should work as written.
But you might consider using Strings to store the phone numbers instead.
On 8/24/08, Robert Kirby <[EMAIL PROTECTED]> wrote:
The value of next on the QueryResult is not being checked. If next
returns false, the message below will be seen as if next had not
been called. The getInt method and other "get" methods could throw
a JessException with a different message when called after next
returns FALSE, but doesn't.
Bob Kirby
At 10:14 AM 8/18/2008, Seyed Hossein wrote:
Hi,
I'm trying to write a program that asks a user his telephone number
in GUI, then searches a database for that phone # using defquery,
and outputs some results. But when I run it I get an error as below.
Jess reported an error in routine QueryResult.get
while executing (call ?result getInt ca)
while executing (printout t ?text crlf (call ?result getInt ca))
while executing deffunction running-query
while executing (running-query ?text)
while executing deffunction read-input
while executing (read-input <Java-
Object:java.awt.event.ActionEvent>).
Message: The cursor is before the first row; you must call next()
before accessing query result .
Since I called next() before accessing query result, I thought the
error might be caused by calling the defquery within a deffunction.
Following is the program I wrote. I'd appreciate any help.
;(watch all)
(import javax.swing.*)
(import javax.swing.JFrame)
(import java.awt.event.ActionListener)
(import java.awt.BorderLayout)
(import java.awt.Color)
(import javax.swing.*)
(import java.awt.*)
(import java.awt.event.*)
(defglobal ?*f* = (new JFrame "Testing"))
(defglobal ?*c* = (?*f* getContentPane))
(defglobal ?*apanel* = (new JPanel))
(defglobal ?*afield* = (new JTextField 40))
(defglobal ?*afield-ok* =(new JButton OK))
(?*apanel* add ?*afield*)
(?*apanel* add ?*afield-ok*)
((?*f* getContentPane) add ?*apanel*
(get-member BorderLayout CENTER))
(?*f* validate)
(?*f* repaint)
(?*c* add (new JLabel "What is the phone number? ")
(BorderLayout.NORTH))
(deftemplate conditions
(slot telnumb)
(slot adr)
(slot esc)
(slot sta)
(slot car))
(deffacts testdata
(conditions (telnumb 4978548) (adr 8) (esc 0) (sta 4) (car 4))
(conditions (telnumb 8754655) (adr 5) (esc 0) (sta 1) (car 6))
(conditions (telnumb 9856211) (adr 1) (esc 0) (sta 7) (car 2))
(conditions (telnumb 5284877) (adr 8) (esc 1) (sta 2) (car 5))
(conditions (telnumb 9845652) (adr 8) (esc 0) (sta 1) (car 1))
)
(defquery search-by-telnumb
"Finds locations with given telephone number"
(declare (variables ?tn))
(conditions (telnumb ?tn) (adr ?ad) (esc ?es) (sta ?st) (car ?
ca)))
(deffunction running-query (?text)
(bind ?result (run-query* search-by-telnumb ?text))
(?result next)
(printout t ?text crlf (?result getInt ca))
)
(deffunction read-input (?EVENT)
(bind ?text (sym-cat (?*afield* getText)))
(running-query ?text)
)
(bind ?handler (new jess.awt.ActionListener read-input (engine)))
(?*afield* addActionListener ?handler)
(?*afield-ok* addActionListener ?handler)
(?*f* setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE))
(?*f* pack)
(?*f* setSize 520 150)
(?*f* setVisible TRUE)
Thank you,
Seyed
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------