Oops, my bad!!
Youve told me before but this time hopefully youve managed to drill the empty catch block concept into my head.
Regarding the no such variable text error - I have not used ?text variable outside the function if I have understood you correctly. I tested the Userfunction with integers (returning the result after adding two integers) and this time it works fine. That is the result is printed.
Jess code:
(deffunction inputintegers (?EVENT)
(bind ?arg1 (sym-cat (?*arg1field* getText)))
(bind ?arg2 (sym-cat (?*arg2field* getText))))
(compute ?result (integer ?arg1) (integer ?arg2))
(printout t ?result ))
(bind ?handler (new jess.awt.ActionListener inputintegers(engine)))
(?*ok* addActionListener ?handler)
Userfunction:
public class test implements Userfunction
{
public String getName () {return "compute";}
public Value call(ValueVector vv, Context c)throws JessException
{
Value abc= vv.get(2).resolveValue(c);
Value def = vv.get(3).resolveValue(c);
int result = abc.intValue(c) + def.intValue(c);
Value res = new Value(result, RU.INTEGER);
c.setVariable(vv.get(1).variableValue(c), res);
return res;
}
}
Here is the code that doesnt work again - for your reference
Jess:
(deffunction inputstring (?EVENT)
(bind ?arg (sym-cat (?*argcombo* getSelectedItem)))
(compute ?text ?arg)
(printout t ?text))
(bind ?handler (new jess.awt.ActionListener inputstring(engine)))
(?*ok* addActionListener ?handler)
Userfunction:
public class test implements Userfunction
{
public String getName () {return "compute";}
public Value call(ValueVector vv, Context c)throws JessException
{
Value abc = vv.get(2).resolveValue(c);
String result = abc.stringValue(c);
Value res = new Value(result, RU.STRING);
c.setVariable(vv.get(1).variableValue(c), res);
return res;
}
}
[EMAIL PROTECTED] wrote:
I think sivan k wrote:
> but I get a no such variable text message when I run the jess
> program - I am not sure why.
...
>
> (compute ?arg1 ?text) {note: ?text holds a value selected from a combobax}
>
If Jess is saying that there's no such variable ?text, then the
variable is not defined in this context. Just as in Java, local
variables defined inside a function, for example, aren't available
to code outside the deffunction.
> I am not sure if the problem is getting the database to connect
through a userfunction or whether it is becasue of the way I retrieve
strings from jess.
...
> catch (SQLException e){throw new JessException ("insert", "SQL Error:"+e.getMessage(),e);
> }
> catch (Exception e) {}
Well, you're not sure because of that empty catch block! If you get a
JessException , a NullPointerException, or a ClassNotFoundException (if
the driver isn't found) they'll all end up in that empty catch block,
and you won't hear about it. That block ought to rethrow as a
JessException too, and then you *will* know what's going wrong!
Never, ever, ever write empty catch blocks, unless you *really* know
what you're doing.
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
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]
--------------------------------------------------------------------
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
