S7 Array Index

S7PP

Member
Join Date
Sep 2010
Location
Toronto
Posts
134
Hi guys, how are you doing?

Quick question about array: if I want to use an array of INT in step 7 with an index, how should I define "index"? DWord or INT or DINT? and how to write it in program?

L Array[index]
T MW20

I'm using STL don't have SCL yet.
 
You can write an FC to perform array accesses though.
Should the aray index be zero based ?

Simple example below:
 
Last edited:
I got what you mean. That's clever.

I was trying to do:

L 9
T #aTest[#index] instead of #aTest[1]

in FB1.

Thanks
 
Last edited:
Code:
 L     P##pArrayOfInts
      LAR1  
      L     W [AR1,P#0.0]
      T     #wDB
      L     D [AR1,P#2.0]
      LAR1  
      L     #iArrayIndex
      SLD   4
      +AR1  
      OPN   DB [#wDB]
      L     W [AR1,P#0.0]
      T     #RET_VAL
      SET   
      SAVE
I don't understand this part of it

L W [AR1,P#0.0] (Why this is saved in wDB???)
T #wDB

L D [AR1,P#2.0] (DW2.0 Contains the value 9 ???)
LAR1
 
Last edited:
All parameters to FC's are passed as 32bit area pointers.

The array is passed as a pointer parameter in FC1. A pointer parameter contains the DB number (16bits)and the area pointer(32 bits) and hence cannot be passed directly to the FC. The editor generates code that copies the DB number and the area pointer into the temp area of FB1 and then passes a pointer to this area when calling FC1. See commented monitored code:

arr5.jpg
 
This loads P##DB1.DBX0.0 in AR1(Adresregister 1)
L P##pArrayOfInt
LAR1

AR1 =Adresregister 1 =/= Local area?



AR1 contains P##DB1.DBX0.0

I thought that this would load the content of DB1.DBW0
L W [AR1,P#0.0]
T wDB

And this i tought would load the content of DB1.DBD2 (dw2= 9 )
L D [AR1,P#2.0]
LAR1
 
This loads P##DB1.DBX0.0 in AR1(Adresregister 1)
L P##pArrayOfInt
LAR1

No it does not. An address register contains an area pointer, it does not contain the DB number.

The monitored code clearly shows AR1 contains 87000038H (V7.0)
The V area is the L area of the preceding block i.e. V7.0 in FC1 is the same as L7.0 in FB1
 

Similar Topics

I am using a function block that has a in/out parameter that is a structure. The structure has an array as one of the elements. I can index the...
Replies
1
Views
737
Sorry for the word salad title, I'm having trouble putting my problem into words. Basically I have two arrays of DINTs, both the same size...
Replies
29
Views
7,969
Hi, Unity has the option to index its arrays between any two numbers; e.g. "ARRAY[13..27] OF INT". I am writing a DFB which needs to take in a...
Replies
3
Views
2,379
I have really hit a wall in a few situations, and asked a professor at a college this question. He said no, but I will ask it here. Can you use...
Replies
30
Views
23,771
I have a variable IDX that varies from 0-10, can I use the following: CONCAT ArrayStr[IDX] ArrayStr[5] Destination To write to a string...
Replies
1
Views
1,477
Back
Top Bottom