Jump to content

Use Int in array


Recommended Posts

Hello,

 

I have an integer that contains the position of a bit in an array that I would to set to 1. Entering numbers in array for the position is possible, but entering my integer isn't. Unilogic says that the integer is longer then the array length. 

 

Is there a possibillity to limit my integer (I know that it isn't longer than my array)?

Link to comment
Share on other sites

Yes, however i don't understand the second sentence.

 

I want to set the bit by using the index value. If you got an array bit[0..8] of all zero's and I do: set array[5] the result will be 000010000.

after that set array[3] will create 001010000 

 

I would like to do so with a integer. Then I could store the position of the bit that I would like to set in the integer and then set it by doing set array[integer]. 

Link to comment
Share on other sites

Binary is usually read from right to left which is why I gave the example of setting the 6th bit as 0 0 1 0 0 0 0 0 in an 8 bit array.

 

Which function are you currently using within UniLogic? There is not a set array function.

 

There is not a built in function for the operation you are describing but it may be possible to create a UDFB that can replicate this process. Since bit arrays are normally operated from right to left will this work or do you need it to work in the opposite way?

Link to comment
Share on other sites

            
            BEGIN_RUNG
                register int RLO1, RLO2;

                /* BusBar Inited RLOs */
                RLO1 = RLO2 =  RLO;
                /* BusBar */

                BEGIN_BLOCK
                    /* 1. Direct Contact */
                    ACC_AND(RLO1, _op_op9F23C19D);
                    /* 2. Set Coil */
                    SET(RLO1, _op_op08576FC6[12]);
                    /* 3. Reset Coil */
                    RESET(RLO1, _op_op9F23C19D);
                END_BLOCK
                BEGIN_BLOCK
                    /* 4. Find in Array */
                    FIND_IN_ARRAY(RLO2, _op_op08576FC6, 20, 0, 1, _op_op7DDFD44C);
                    /* 5. Store */
                    _ERROR_IN_ELEMENT(Error in Element ID = 855f5872-dd58-4b3c-83cb-9ceac16033c3, Message = Error during operand compile )
                END_BLOCK
                /* End Junction */
            END_RUNG

Can you see what I display here? Don't know another way to display. 

 

I just want to store a certain value in an array by entering not a number but an integer between the [ ]

 

Maybe writing a UDFB could be the solution, but is it also possible for multiple arrays?

Link to comment
Share on other sites

Hi,

The Arrays in UniLogic works in a way that you can give a name to items inside an array.

Given that, assume the following situation:

 

Array_Int with Member:

Hello  // index 0

World // Index 1

 

Now, the lexer let you access a cell in the array by either:

Array_Int[0]

or

Array_Int[Hello]

 

 

UniLogic prevents the existance of 2 tags with the same name, on the same scope (You can have 2 local tags, each on a different function with the same name, but having a global tag with that name would create a conflict, because the compilier will not know to which tag you actually refer).

 

 

Now, consider the following scenario:

I also have a tag called Hello.... So if I write Array_Int[Hello], then I want to access index 0, or the index with the value of the Hello Tag?

 

 

This is one of the resons why we don't allow indirect access to array cells in the way ou have mentioned.

About the error you got.

The Compiler/Lexer looks for a member called Integer_Tag (or what ever your tag is named), but since it can't find any array member with that name, then it gives you that error (which is in this case, not clear and not accurate).

 

 

 

So wait, that means that you can't access an array cell indirectly??

Well, you can, but not in the way you've tried.

 

 

Try using "Load from Array" for getting a value indirectly from an array, and "Store in Array" for setting a value indirectly to an array.

 

:-)

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...