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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to receive value from checkbutton...HELP!!! 1

Status
Not open for further replies.

FreddieBlassie

Programmer
Dec 11, 2001
20
US
I am trying to figure out how to recieve the value from a checkbutton when that button is in the on position and a user clicks an entry button. I've been trying a bunch of different methods to get the value to be set in the myproc2 procedure but am having no luck. This is a snippet of the code that i just ran. I have been adjusting it various ways to try and get it right. When I run it as it is right now i get back an error message which reads "Invalid command name ::Chec0" Please help if you can.




proc myproc2 {} {

set txport $[::Chec$b]
ixPuts "txport"

}



toplevel .top

wm title .top "hi"
wm geometry .top 175x300+25+25


frame .top.fr2 -bd 10 -width 5i -height 5i
pack .top.fr2 -side top -ipady 10

frame .top.fr -bd 10 -width 5i -height 5i
pack .top.fr -side top -ipady 10


frame .top.fr3 -bd 10 -width 5i -height 5i
pack .top.fr3 -side bottom -ipadx 50 -ipady 50


message .top.fr.r -width 4i -text "Select port for Testing Station 1"
pack .top.fr.r



###############loop to create buttons and pass value 2 ###############proc myproc2

set b 0

foreach item $portList {


checkbutton .top.fr.$item -text $item -onvalue $item -variable [::Chec$b]


pack .top.fr.$item




incr b

}


message .top.fr2.r -width 4i -text "Enter name for Testing Station 1"
pack .top.fr2.r
entry .top.fr2.entry1 -width 10 -relief sunken -textvariable ::Station1
pack .top.fr2.entry1

button .top.fr3.enter2 -text Enter -command myproc2
 
if "chec$b" (or "::chec$b") is a variable, why do you have it enclosed in []? Bob Rashkin
rrashkin@csc.com
 
In the for loop I'm trying to increment the value of b for each checkbutton I create. If I take the [] off, it only sees the variable for the buttons created as ::Chec (Says can't read "::Chec" no such variable) when I am trying to get it to see ::Chec0, ::Chec1,...etc. However, when I do it with the [] it says "illegal command Chec1" which I don't understand because it should be a legitimate variable I would think. But then I'm not a TCL expert.
 
Well, I think using "" as in "::chec$b" would work better. I just tried:

set chec0 0
>0
set chec1 1
>1
set b 0
>0
set "::chec$b"
>0
set b 1
>1
set "::chec$b"
>1 Bob Rashkin
rrashkin@csc.com
 
I believe I tried that before too. I just tried it now and received a stack trace error which reads: can't read "b": no such variable while executing set txport "::Chec$b"
I believe the value is being set in the for loop, but when I try to view it in the procedure after the button is clicked, it doesn't associate $b with the value.




proc myproc2 { } {

set txport "Chec$b"
ixPuts "txport"

}



toplevel .top

wm title .top "hi"
wm geometry .top 175x300+25+25


frame .top.fr2 -bd 10 -width 5i -height 5i
pack .top.fr2 -side top -ipady 10

frame .top.fr -bd 10 -width 5i -height 5i
pack .top.fr -side top -ipady 10


frame .top.fr3 -bd 10 -width 5i -height 5i
pack .top.fr3 -side bottom -ipadx 50 -ipady 50


message .top.fr.r -width 4i -text "Select port for Testing Station 1"
pack .top.fr.r



##################################################
#########################for loop for checkbuttons

set b 0

foreach item $portList {


checkbutton .top.fr.$item -text $item -onvalue $item -variable "Chec$b"


pack .top.fr.$item




incr b

}

message .top.fr2.r -width 4i -text "Enter name for Testing Station 1"
pack .top.fr2.r
entry .top.fr2.entry1 -width 10 -relief sunken -textvariable ::Station1
pack .top.fr2.entry1

button .top.fr3.enter2 -text Enter -command myproc2
 
Oh. I think this calls for "uplevel", or global, or passing $b as an argument. I don't think your proc knows what variable "b" is. Bob Rashkin
rrashkin@csc.com
 
I think I may have it anyways. Maybe i made it more complicated than it needed to be. I'll look into the uplevel command though, but it initially seems like the following code is going to work. I'll keep hacking away at it anyways though.





proc myproc2 { } {


if { $::Chec1 != 0 } {

set txport $::Chec1

ixPuts "$txport"
} else {


}

}

toplevel .top

wm title .top "hi"
wm geometry .top 175x300+25+25


frame .top.fr2 -bd 10 -width 5i -height 5i
pack .top.fr2 -side top -ipady 10

frame .top.fr -bd 10 -width 5i -height 5i
pack .top.fr -side top -ipady 10


frame .top.fr3 -bd 10 -width 5i -height 5i
pack .top.fr3 -side bottom -ipadx 50 -ipady 50


message .top.fr.r -width 4i -text "Select port for Testing Station 1"
pack .top.fr.r

set b 0


###################################################
##########################for loop

foreach item $portList {


checkbutton .top.fr.$item -text $item -onvalue $item -offvalue 0 -variable ::Chec1


pack .top.fr.$item




incr b

}

message .top.fr2.r -width 4i -text "Enter name for Testing Station 1"
pack .top.fr2.r
entry .top.fr2.entry1 -width 10 -relief sunken -textvariable ::Station1
pack .top.fr2.entry1

button .top.fr3.enter2 -text Enter -command myproc2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top