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

Reference a variable with partially substituted name

Status
Not open for further replies.

Pavel47

Technical User
May 20, 2010
1
CH
Hello,

How to reference a variable if its name includes substitution ?

foreach item {aaa bbb ccc} {
checkbutton $frm_FRAME1.chkbt_$item \
-variable var_$item -text $item \
-command "puts $var_$item"
pack $frm_FRAME.chkbt_$item -anchor w
}

Execution of this code generate error:
can't read "var_": no such variable

Thanks in advance,

Pavel
 
I've always found I need to build it up:
Code:
set strA var_
append strA $item
....

Then, in the -command "puts $var_$item", you need to delay substitution:
Code:
-command {puts $strA}

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top