<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">The event handling function works
asynchronously (may be during the execution of another
function....)<br>
instruction like res=<font color="#000000" face="verdana,
sans-serif">return (x*2</font>) will store the result in the
current execution context which unknown if Scilab is not at
prompt level when the handling function is executed <br>
<br>
<br>
<br>
It is better to use global variable:<br>
<div><font face="verdana, sans-serif"><font
style="color:rgb(0,0,0)">function </font><span
style="color:rgb(0,0,0)">myEventHandler(win,x,y,ibut)<br>
global res<br>
</span></font></div>
<div><font color="#000000" face="verdana, sans-serif">res=x*2</font></div>
<div><font color="#000000" face="verdana, sans-serif">endfunction<br>
<br>
You can then recover the value everywhere by<br>
</font><font color="#000000" face="verdana, sans-serif"><font
face="verdana, sans-serif"><span style="color:rgb(0,0,0)">global
res;disp(res)<br>
<br>
<br>
</span></font>or to store the result into the user data field
of the figure in which the evenet handler has been called<br>
</font><br>
<div><font face="verdana, sans-serif"><font
style="color:rgb(0,0,0)">function </font><span
style="color:rgb(0,0,0)">myEventHandler(win,x,y,ibut)<br>
fig=get_figure_handle(win)<br>
set(fig, "user_data", struct("myres",x*2))<br>
</span></font></div>
<div><font color="#000000" face="verdana, sans-serif">endfunction<br>
</font></div>
<font color="#000000" face="verdana, sans-serif">You can then
recover the value everywhere using<br>
</font><br>
<font color="#000000" face="verdana, sans-serif"><font
face="verdana, sans-serif"><span style="color:rgb(0,0,0)">fig=get_figure_handle(win)</span></font><br>
</font></div>
<div><font face="verdana, sans-serif">disp(fig.user_data.myres)<br>
</font></div>
<div><font face="verdana, sans-serif"><br>
</font></div>
<br>
Serge Steer<br>
<br>
<br>
Le 30/11/2012 14:26, walid shouman a écrit :<br>
</div>
<blockquote
cite="mid:CADaxruJ-HE1WBWZv5ZOOfHphBHcBzjnDMiZpVLquxWNCVD4qGQ@mail.gmail.com"
type="cite">
<div dir="ltr"><font color="#000000" face="verdana,sans-serif">how
can i return the a value from an event handling function</font>
<div><font color="#000000" face="verdana,sans-serif"><br>
</font></div>
<div><font color="#000000" face="verdana,sans-serif"><br>
</font></div>
<div><font color="#000000" face="verdana,sans-serif">ie: <br>
<br>
</font></div>
<div><font color="#000000" face="verdana, sans-serif"><span
class="">seteventhandler</span><span class="">('myEventHandler(win,x,y,ibut)')</span></font></div>
<div><font face="verdana, sans-serif"><font
style="color:rgb(0,0,0)">function val=</font><span
style="color:rgb(0,0,0)">myEventHandler(win,x,y,ibut)</span><br>
</font></div>
<div><font color="#000000" face="verdana, sans-serif">return x*2</font></div>
<div><font color="#000000" face="verdana, sans-serif">endfunction</font></div>
<div><font face="verdana, sans-serif"><br>
</font></div>
<div><font face="verdana, sans-serif"><br>
</font></div>
<div><font><font face="verdana, sans-serif">where should i find
"val" to use it later in the code ?</font></font></div>
<div>
<div><br>
</div>
-- <br>
<br>
Sincerely,<br>
Walid E. Shouman<br>
<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
</body>
</html>