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!

Radiobuttons created using a for loop 1

Status
Not open for further replies.

cathyboo

Programmer
Aug 16, 2011
2
IE
Hi,

I have created three radiobuttons per day for each day of a month using an array using the following code for January, (each month is a tab in a notebook)

set pane [$nb getframe jan]
set mth 1
set i 0
for {set dy 1} {$dy <= 31} {incr dy} {
set ::mark($dy) "$marker($dy)"
set ::dy $dy
if {$::mark($dy) == "Q"} {set mcol "green"}
if {$::mark($dy) == "D"} {set mcol "red"}
if {$::mark($dy) == "N"} {set mcol "black"}
label $pane.jan_lbl_$dy -text "[clock format [clock scan "$dy$year" -format {%j%Y}] -format {%d %b %Y}] \t [format %03.0f $dy] \t" -foreground $mcol
radiobutton $pane.jan_rad_q$dy -text "Q quiet" -variable ::mark($dy) -value "Q" -command {
set mcol "green"
.qdn.nb.fjan.jan_lbl_$dy configure -text "[clock format [clock scan "$dy$year" -format {%j%Y}] -format {%d %b %Y}] \t [format %03.0f $dy] \t" -foreground $mcol
} -foreground green

radiobutton $pane.jan_rad_q$dy -text "D disturbed" -variable ::mark($dy) -value "D" -command {
set mcol "red"
.qdn.nb.fjan.jan_lbl_$dy configure -text "[clock format [clock scan "$dy$year" -format {%j%Y}] -format {%d %b %Y}] \t [format %03.0f $dy] \t" -foreground $mcol
} -foreground red

radiobutton $pane.jan_rad_q$dy -text "N normal" -variable ::mark($dy) -value "N" -command {
set mcol "black"
.qdn.nb.fjan.jan_lbl_$dy configure -text "[clock format [clock scan "$dy$year" -format {%j%Y}] -format {%d %b %Y}] \t [format %03.0f $dy] \t" -foreground $mcol
} -foreground black

grid $pane.jan_lbl_$dy -column 0 -row $i
grid $pane.jan_rad_q$dy -column 1 -row $i
grid $pane.jan_rad_d$dy -column 2 -row $i
grid $pane.jan_rad_n$dy -column 3 -row $i
incr i
}

The idea is to select a value for each day as being one of the three options available & colour code the day according to the option selected. However, whichever day I select the only change occurs in the last day. Is there a way to capture the value of $dy according to which radiobutton was selected. $marker($dy) contains values of either Q, D, or N to give initial set which radiobutton should be activated, these values were read from a file containing values for the whole year.

I have been struggling with this for a few days and would really appreciate any help with this.
 
I think you're having a problem with scope. Your in-line command (in the radiobutton configuration) uses "$dy" inside curly braces, "{}". That is the most delayed substitution, meaning that by the time the value of "dy" is passed into the command, the loop is long over and the value is 31. It's always better, if for no other reason than to keep your head straight, to use proc blocks.

_________________
Bob Rashkin
 
Thanks for the answer! I came up with a solution by using quotation marks, " " instead of the { } but I prefer your idea of using procedures, for exactly the reason you said. Everything is far easier to read in procs. Will try that now!

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top