Re: Substitution error?



Eduardo Peña wrote:
set topf [frame $frame.topf]
for {set i 0} {$i < 10} {incr i} {
    set a$i [TitleFrame $topf.a$i -text "Title $i"]
    pack $a$i
}

The problem is that $a$i is the concatenation of the value of a and the value of i, not the value of a$i. You can't say ${a$i} either, because that'd be the value of a-dollar-i, which doesn't exist.


1. You can get the value of the "contructed" variable name like so:

	pack [set a$i]

This allows Tcl to substitute the $i, giving a0, a1..., then gets the value of the constructed variable name.

2. You could get rid of the intermediate variable altogether:

	pack [TitleFrame $topf.a$i -text "Title $i"]
.