[scilab-Users] variables from TCL in Scilab
    François Vogel 
    fvogelnew1 at free.fr
       
    Fri Mar 26 21:26:13 CET 2010
    
    
  
marcin.wozniczka Gazeta.pl said on 26/03/2010 20:00:
> Example of this function in TCL is below:
Please stop trying formatting your code when posting. Italics is 
really awful to read (my opinion) and does not ease error detection 
(just a fact).
> /for {set i 1} {$i <= ($::npkt)} {incr i} {/
> /  pack [entry .pol.n.nr$i -width 7 -justify right
> -textvariable nr$i -validate key -vcmd {expr {[string is double %P] &&
> ![string match ""0*"" %P] && [string len %P] <=7}}]/
> /}/
Why  [string match ""0*"" %P]  ?
This triggers an error in Tcl. Use  [string match "0*" %P]
> /function []=calc()/
> /n=evstr(TCL_GetVar("npkt"));/
> /for i=1:n/
> /    b ="nr''+string(i)      //name of variables in TCL/
> /    nr_pkt(i)=evstr(TCL_GetVar("b"));/
> /end/
> /endfunction/
Read carefully your line:
 > /    b ="nr''+string(i)      //name of variables in TCL/
This cannot work. Italics does not let you see the problem.
What works is:
       b ="nr"+string(i)      //name of variables in TCL/
> After executed program inScilab and used this finctionI have information:
> / !--error 999 /
> /TCL_GetVar: Could not read Tcl Variable./
> /at line      14 of function liczpol called by : /
> /liczpol()/
> /while executing a callback/
> /
> /
> Could anyone know what is wrong with this function?
Yes.
nr_pkt(i)=evstr(TCL_GetVar("b"));
tries to retrieve variable named "b" from Tcl.
You rather want:
nr_pkt(i)=evstr(TCL_GetVar(evstr("b")));
Also your function cal should return a result, otherwise nr_pkt is 
lost upon endfunction.
Try:
function nr_pkt=calc()
instead of
function []=calc()
> And I have question about second function which should return calculated
> variables to TCL. Is this function is write correctly?
> /function []=result()/
> /n=evstr(TCL_GetVar("nrxp"));/
> /for i=1:n/
> /  x/
> ='xp'+string(i)     //name of variables in TCL
> //
> /
> /
> TCL_SetVar("x",r(i))   //r(i) are results
> /
> /
> /end/
> /endfunction/
Same issue. You probably want:
TCL_SetVar(evstr("x"),r(i))
and not:
TCL_SetVar("x",r(i))
Francois
    
    
More information about the users
mailing list