Re: Accessing Array Elements within [if-else]



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.


.



Relevant Pages

  • Re: Accessing Array Elements within [if-else]
    ... your procedure PortCtr is called several times and creates an array ... Port on procedure scope with some array elements ... if in one call the array element Portexists, ...
    (comp.lang.tcl)
  • rs232...
    ... Hello Scott and everyone else who will read this post. ... //immediatelly assigned to this array. ... // from the rs232 port), ... I thank Scott and all members of the news groups that have helped me on the ...
    (microsoft.public.vc.language)
  • Re: Easier initializing of blockram (spartan3)
    ... >> (including parity bus) at the port at adress A. This is a plain mapping ... > array passed as a generic and generate the proper init_xx attributes. ... init_000(31 downto 0); ...
    (comp.arch.fpga)
  • Re: rs232...
    ... 'j' for non-equality to BYTESTOREAD in the end of 'do' loop, ... #define BYTESTOREAD 25 //Depicts the amount of bytes to read! ... //immediatelly assigned to this array. ... // from the rs232 port), ...
    (microsoft.public.vc.language)
  • Re: building on your own a large data storage ...
    ... RAID-5 array because doing I/O on two devices on the same IDE ... primary IDE port and one on the secondary IDE port. ... understanding the trade-offs (partioning an array of disks vs. ... When a fan goes ...
    (comp.sys.ibm.pc.hardware.storage)