Re: Accessing Array Elements within [if-else]
- From: "MartinLemburg@UGS" <martin.lemburg.ugs@xxxxxxx>
- Date: 8 Feb 2007 04:39:44 -0800
Hi,
1. your procedure PortCtr is called several times and creates an array
Port on procedure scope (local) with some array elements
2. so everytime your procedure PortCtr is call the array Port is
unknown and will created again and again and ...
3. if in one call the array element Port(0) exists, but in another
call Port(0) won't exists if Counter never occurred to be 0
So change the head your procedure PortCtr to:
proc PortCtr {PortNr Counter} {
global Port;
if {$Counter==0} {
...
}
}
Afterwards the procedure PortCtr will remember each array element of
Port and the "else" block won't run into this mentioned error!
Best regards,
Martin Lemburg
UGS - a Siemens Company - Transforming hte Process of Innovation
On Feb 8, 12:14 pm, "SuNnY" <esu...@xxxxxxxxx> wrote:
On Feb 8, 11:51 am, "slebet...@xxxxxxxxx" <slebet...@xxxxxxxxx> wrote:
On Feb 8, 11:01 am, "SuNnY" <esu...@xxxxxxxxx> wrote:
if {$Counter==0} {
for {set i 0} {$i<=$Counter} {incr i} {
This piece of code is is exactly equivalent to:
set i 0
Since it is only executed when $Counter==0, the second argument to the
for loop is logically: {$i<=0}. Which means the for loop iterates
exactly once. Which means you can completely remove the for loop. Is
this *really* what you want?
set StrChk [set Port($j)] <--------------
While this works (and some would consider old-school) it's perhaps
more readable written as:
set StrChk $Port($j)
The error :-
cant read "Port(0)" : no such variable
while executing "set Port($j)".........
The error simply says that the variable Port(0) doesn't exist. Now,
this may be caused by one of 2 things:
1. The array Port doesn't exist.
2. The key "0" doesn't exist in the array Port.
Are you sure the array Port exists? Is it a local or global? If global
have you remembered to import it into the current proc using [global
Port]? If it is local then are you sure you've created the array Port
before using it? In either case, are you sure you've created the
element in array Port whose key is "0"?
Hi !!
I will make those changes, its just becoz of lack of much exp with
Tcl, i went that way.
Well if you observe, I have created Port with 0 key in the if block,
and try to access Port(0) in else block.
Do you think declaring global will work. how do you declare?? outside
the proc??
I will try and let ya know.
.
- Follow-Ups:
- Re: Accessing Array Elements within [if-else]
- From: SuNnY
- Re: Accessing Array Elements within [if-else]
- References:
- Accessing Array Elements within [if-else]
- From: SuNnY
- Re: Accessing Array Elements within [if-else]
- From: slebetman@xxxxxxxxx
- Re: Accessing Array Elements within [if-else]
- From: SuNnY
- Accessing Array Elements within [if-else]
- Prev by Date: Re: Accessing Array Elements within [if-else]
- Next by Date: Re: Does canvas have direct C-APIs for commands like "create rectangle" ?
- Previous by thread: Re: Accessing Array Elements within [if-else]
- Next by thread: Re: Accessing Array Elements within [if-else]
- Index(es):
Relevant Pages
|