Re: Substitution error?



Eduardo Peña wrote:
Hi,

I have a top frame followed by a loop:

*******************************************
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
}
*******************************************

But i have an error:
can´t read "a": no such variable while executing pack $a$i

My questions are:
How i can pack this frames/titleframes in a loop "n" times?
What happend with a for-loop in local use of variables in frames/subframes?

pack [set a$i]

If you use arrays it becomes easier:

    set a($i) [TitleFrame...]
    pack $a($i)

Useful Rule O' Thumb: avoid dynamic variable names unless you're certain you absolutely need them.
.




Relevant Pages