Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
20.9.2014 - We have just updated our course layouts and descriptions and added our 2015 schedule.

Tk/Wish Script problem

Posted by neo (The Architect), 21 January 2005
I have a problem with variables in Tk.
I have 2 global variables (string) and want to have a common procedure to update any one of the variabels depending on the arguments passed.
I pass the global variable that i need as an argument and then using 'upvar' try to change it in the procedure but it does not happen.
I use
Code:
upvar #0 $argvar myvar;
set myvar "newval";

Any idea how this is correctly done?



Posted by neo (The Architect), 21 January 2005
I have a procedure to display error messages which are stored in a err Array (global).
My procedures may call this error procedure with an index name/number and i want the appropriate error message to be printed out.
The upvar thing is not working for me , I do not know why.
Does any one have some example code of this?
Any help appreciated.

Posted by admin (Graham Ellis), 22 January 2005
If you're using a global variable, you don't need to pass it as an argument.  The main point of global variables is that they don't have to be passed around - simply declare it as global in the proc.

The following is untested - I'm out of the office using borrowed and llimited facilities, but:

proc shmsg {which} {
    global errmsgs
    puts $errmsgs($which)
    }

set errmsgs(oops) "Warning - slight problem"
set errmsgs(yikes) "Error - program cannot proceed"
set errmsgs(!!!) "Catastrophic failure)

shmsg(yikes)

This example should set up a global array and then the shmsg proc will print out one of the elements from it depending on the parameter passed.

Posted by neo (The Architect), 22 January 2005
Yeah that is similar to what i've done now.  

Posted by neo (The Architect), 23 January 2005
I have several variables which i first check to see if they are empty or not.
Right now i do that using a series of 'if' commands (one for each variable. Something like
Code:
if {first $var1 check } {
 return -1;
}
if {first $var2 check } {
 return -1;
}
if {first $var3 check } {
 return -1;
}
if {first $var4 check } {
 return -1;
}

Is there an easier way to do this?

Posted by neo (The Architect), 23 January 2005
Another problem with sockets now.
Code:
    after $timeOutLimit {set isConnected $timeOutLimit};
    set ftpCtrlSocket [socket -async $McName $PortNo];
    fileevent $ftpCtrlSocket writable {set isConnected 1};

This code works fine when the given port is correct otherwise it gives an error when i try to read from the port after this

Posted by admin (Graham Ellis), 24 January 2005
on 01/23/05 at 13:00:54, The Architect wrote:
I have several variables which i first check to see if they are empty or not.
Right now i do that using a series of 'if' commands (one for each variable. Something like
Code:
if {first $var1 check } {
 return -1;
}
if {first $var2 check } {
 return -1;
}
if {first $var3 check } {
 return -1;
}
if {first $var4 check } {
 return -1;
}

Is there an easier way to do this?


Yes - a foreach loop .... something like ....

Code:
foreach thing "$var1 $var2 $var3 $var4" {
if {first $thing check} {return -1}
}


And you don't need the semicolon to end your statements in Tcl - works fine, but looks like you're really a C programmer  

Posted by neo (The Architect), 24 January 2005
on 01/24/05 at 11:36:58, Graham Ellis wrote:
And you don't need the semicolon to end your statements in Tcl - works fine, but looks like you're really a C programmer  


Yeah you got that right  
I'll check the code and let you know soon.

Posted by neo (The Architect), 24 January 2005
Err... any help forthcoming on the sockets problem.  

Posted by admin (Graham Ellis), 24 January 2005
Oh - I had overlooked that one - sorry.   It's a huge help if you can give each new subject its own thread, otherwise question "no 2" will get lost in all the answers to question "no 1".

This version of the forum software doesn't let me split a thread; if you would care to start a new thread and repost the question, that would be great.    Thanks!


Posted by neo (The Architect), 25 January 2005
Started it as a separate thread here  



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

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