Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call a procedure in tcl/tk 1

Status
Not open for further replies.

bg30

Vendor
Jun 9, 1999
2
CN
hi there,<br>
<br>
i'm new to tcl/tk and am learning this language, i know this is a silly question, but i just can't fix the<br>
problem. look at the following lines.<br>
<br>
set i 100<br>
set ok [myProc $i]<br>
<br>
proc myProc {n} {<br>
puts i'm in myProc, n is $n<br>
}<br>
<br>
when i run this script, i got <br>
<br>
invalid command name "myProc"<br>
while executing<br>
"myProc $i"<br>
invoked from within<br>
"set a [myProc $i]"<br>
(file "test.tcl" line 2)<br>
<br>
what wrong with this script, i just can't find out.
 
put the codes for your procedure before <br>
calling them.<br>
<br>
this, I guess, is call good programming practice.<br>
<br>
<br>
u will probably run into errors after doing that.<br>
'Cos your 'puts' in the procedure have some minor<br>
syntax error.<br>
<br>
try and see what u can find out...<br>
cheers..
 
I agree with slok. You need to put your procedure<br>
declaration before you invoke it.<br>
<br>
Also, you need quotes around the string you are <br>
passing to puts. ( puts "i'm in myProc, n is $n" )
 
For general help with tcl/tk look at<br>
There's a quick reference guide which you can download. It's in postscript format so I'm not sure if any windows app that can read postscript file I think maybe acrobat reader can. On any other OS there's millions of utilities available
 
Slok & Mart R Right.. <br>BUt i have Used a procedure before writing its code in several of my scripts and they worked then why isn't this simple script working..and moreover there is no syntax error in that program except fot &quot; puts&quot; so why isn't it WORKING ?!!
 
If I cut and paste your code as listed in the first link, I get the expected<br>error message caused by an invocation of a procedure before its<br>declaration. <br><br>If I declare the proc before I invoke it:<br>#!/usr/bin/tcl<br>set i 100<br><br>proc myProc {n} {<br>puts &quot;i'm in myProc, n is $n&quot;<br>}<br><br>set ok [myProc $i]<br><br>And run the code, I get:<br># ./temp.tcl<br>i'm in myProc, n is 100<br>#<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top