Training, Open Source Programming Languages

This is page http://www.wellho.net/mouth/2040_.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Error: Cant read xxxxx: no such variable (in Tcl Tk)

If you set a Tcl (Tcl/Tk) variable within a proc, or within the callback command of a widget, that variable does not exist at run time until you have run the proc or callback procedure, or until you have initialised the variable in some other way.

Let's see a Tk example. I have created a window with two buttons. The one labelled "Press me first" creates a variable called pressed than contains the value hello. And the one labelled "Press me second" updates the label called .report with the value that's stored in the variable.


If you run the program , pressing the first button first, and the second button second, it works as illustrated at the top of this entry to the left and right.

But if you press the button labelled press me second without pressing the button labelled press me first, you get this:



Here is the complete code that I used to generate these examples:

button .demo1 -text "Press me first" -command {
  global pressed
  set pressed hello
  }
button .demo2 -text "Press me second" -command {
  global pressed
  .report configure -text $pressed
  }
button .quit -text exit -command exit
label .report -text "---"
pack .demo1 .demo2 .report .quit


What should you do if you are getting a message such as "Error: Can't read 'pressed': no such variable"?
• check your logic
• if necessary, initialise the variable outside your callbacks
• check that you have used global if necessary (in order to share a variable from within a proc with the same variable of the same name in the main code)
• send me an email to say you found this article useful!

We run regular public Tcl and expect courses and Tcl/Tk and wish courses. For a full schedule of all of our public courses, see here




This short article was written in response to an emailed question. I answered:

It looks like you are trying to use the contents of a variable before you set it - remember that variables in Tcl are only created when you actually run the code that sets them, so a definition within a proc will only cause the variable to be created when the proc is actually run.

Your question is a very good one, and you have provided inspiration for a full example on my blog - see:

http://www.wellho.net/mouth/2040_Error-Cant-read-xxxxx-no-such-variable-in-Tcl-Tk-.html


Graham
(written 2009-02-14, updated 2009-02-15)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T241 - Tcl/Tk - Tcl on the Web
  [1785] What is running on your network? (tcl and expect) - (2008-09-04)
  [2238] Handling nasty characters - Perl, PHP, Python, Tcl, Lua - (2009-06-14)
  [2429] Tcl scripts / processes on a web server via CGI - (2009-09-27)
  [4461] Reading from a URL, and reading Json, from your Tcl script - (2015-03-12)

T216 - Tcl/Tk - Introduction to Tk
  [595] Add a friendly front end with Tk - (2006-02-08)
  [4208] Tcl + Tk (Wish) - an introduction and revision example - (2013-11-15)
  [4460] Using Object Oriented Tcl and the Tk toolkit together - real life example - (2015-03-12)


Back to
The Invoker
Previous and next
or
Horse's mouth home
Forward to
httpd, Tomcat and PHP course enhancements
Some other Articles
Please Trouble me
Confidence, Customer Service and Tourism in Melksham
Wiltshire Rail Service Update
httpd, Tomcat and PHP course enhancements
Error: Cant read xxxxx: no such variable (in Tcl Tk)
The Invoker
Sticky Sessions with mod_jk (httpd to Tomcat)
The Interview and The Lift
Java Tag Libraries / how they work / Tomcat Deployment
1234567890 ... coming up on Friday 13th
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2040_.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb