Problem with Queues

Hello,

 

I am working with Queues in FB5. The Queues work fine when I give a static name to the queue. However, when I need to define queue’s names which contain the value of a variable (namequeue_%number%), it seems that all of the queues that are related with namequeue_% number % share the same memory address. If I have for example namequeue_1, namequeue_2 (where 1 and 2 are values of  %number%), when I log the content of these queues they both have the same content (the content of the last one).

 

When a queue is defined in PB5, in the build log we can see “Queue [namequeue_%number%] defined.” Maybe the definition should be with the value of the variable instead of using the name of the variable. It seems that the definition should be “Queue [namequeue_1] defined”, so that each instance can have their one memory address.

 

You can try to reproduce this issue using the following pseudo code:

 

For [number] = 1 To 2 Step 1

            Define queue [namequeue_%number%]

                        Clear Queue [namequeue_%number%]

                        If [%number%] =1

                                    Push items on Queue [namequeue_%number%] (Push a, b, c)

                        Else

                                    Push items on Queue [namequeue_%number%] (Push x, y, z)

 

For [number] = 1 To 2 Step 1

            Log items on Queue [namequeue_%number%]

 

The log will show:

namequeue_1 = x, y, z (it should be namequeue_1 = a, b, c)

namequeue_2 = x, y, z

 

Please let me know your comments about this issue.

 

Thanks.

Rosalva.

Hi Rosalva,

Sorry to tell you this, but you can’t (or at least shouldn’t) use variable in the queue name. They work quite differently to variables - only one queue can be defined by a single “Define Queue” action. So, unfortunately the workaround is that you need to declare each of the queues you want to use with separate Define Queue actions.

cheers,
tate