Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6327717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:19:48+00:00 2026-05-24T17:19:48+00:00

I am running into problems while trying to access array inside an expr .

  • 0

I am running into problems while trying to access array inside an expr. The code which reproduces the error is shown below which is adapted from Donal Fellows answer to my earlier question.

namespace eval Ns {
}

proc Ns::main_routine {} {
  global cb

  array set cb {
    c1 0
    c2 0
    c3 0
    c4 0
  }

  checkbutton .c1 -text "C1" -variable     cb(c1)
  checkbutton .c2 -text "C2" -variable     cb(c2)
  checkbutton .c3 -text "C3" -variable     cb(c3)
  checkbutton .c4 -text "C4" -variable     cb(c4)

  grid .c1 -sticky w
  grid .c2 -sticky w
  grid .c3 -sticky w
  grid .c4 -sticky w

  # _After_ initializing the state...
  trace add variable cb(c1) write Ns::reconfigureButtons
  trace add variable cb(c2) write Ns::reconfigureButtons
  trace add variable cb(c3) write Ns::reconfigureButtons
  trace add variable cb(c4) write Ns::reconfigureButtons
}

proc Ns::reconfigureButtons args {
  global cb

  # this one works
  set state "normal"
  if { $cb(c1) } {
    set state "disabled"
  }
  .c2 configure -state $state

  # this one does not
  #.c2 configure -state [expr $cb(c1) ? "disabled" : "normal"]
  #.c4 configure -state [expr $cb(c1)||$cb(c3) ? "disabled" : "normal"]
}

Ns::main_routine

I want to fix the following line in the above code

.c2 configure -state [expr $cb(c1) ? "disabled" : "normal"]

When I use the above line I get the following error:

can't set "cb(c1)": invalid bareword "disabled" in expression "1? disabled : normal";

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:19:49+00:00Added an answer on May 24, 2026 at 5:19 pm

    You should always put {braces} around expressions, as that stops double substitution, leaving the "quotes" to do their proper purpose. You also boost the security and speed of your code by doing that, and have done since at least Tcl 8.0 (over a decade ago); before that, performance reasons meant that many people omitted braces, but that was a truly terrible habit.

    In short, don’t use:

    .c2 configure -state [expr  $cb(c1) ? "disabled" : "normal" ]
    

    But rather use this:

    .c2 configure -state [expr {$cb(c1) ? "disabled" : "normal"}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been running into a problem while trying to delete uploaded images. The error
I'm running into a problem while trying to compile my code: D:\workspace>javac DbConnect.class javac:
Hi guys I'm trying to integrate the tinymce plugin however I'm running into problems
I have been trying to learn Erlang and have been running into some problems
I'm trying to work through the problems on projecteuler.net but I keep running into
I'm running into problems trying to pass absolute URIs as parameters with clean URLs
I am evaluation dapper but i already running into some problems. I am trying
I'm running into problems implementing statuses for a model. This is probably due to
I'm running into some problems using my .NET 4.0 libraries in .NET 2.0 applications.
I have a .NET 2.0 server that seems to be running into scaling problems,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.