indirect pointing at the UDT

martin3885

Member
Join Date
Aug 2005
Location
Saarland
Posts
144
Hi,
if I want to point indirect to a UDT which is in an array how can I do it?
I can do it not indirectly:
I have declaration in DB10: Objekt Array[1..100] of UDT1, so DB10.Objekt[1] points at the first element of my array.
But what if I want to point at this element indirect, and then to give the begining address to the any pointer?

Regards.

Martin
 
First I assume that you use S7.
It's not possible to directly access indirectly given data in DB. :)
You have to open the DB first and then you can access indirectly data in it.
However you can create FC/FB with an input of type POINTER, and then assign "DB10.Objekt[1]" to this input.
 
Martin, do you mean you want to pass an any pointer as a parameter but that instead of putting "DB10.Objekt[1]" as the parameter, you want to contruct the any pointer yourself and pass this to the function ?

If so, create a temporary variable of type any and then proceed to populate the any pointer with the length,type, DB and area pointer yourself. You will still have to reference "DB10.Objekt[1]" somewhere in order to determine the any pointer parameters.

On a more general note, could you explain why you need to do this - it would give a more information for suggesting a solution.
 
Hi,
I have more then one DB with objects of UDT type. The easiest way would be to do DB[nr].Objekt[1] and then to increment nr to reach objects in a next DB, but it is imopssible. I mean all the DBs have Objekt[1] under the address 0.0, but the array Objekt[1..100] in each DB consist of different UDTs. I mean in DB1 Objekt[1..100] is of type UDT1, in DB2 Objekt[1..100] is of type UDT2 and so on. So, I thought about indirect adressing.
I need this to calculate the lenght of UDTs.
Other thing is that I need to have DBs of UDT type, without array of UDTs, and I need also to know the lenght of this UDT. That is why I try to give the adress of UDT to ANY pointer.

regards

Martin
 
OK. I see.
It's not possible to get size of a UDT at runtime directly (or I don't know such a solution).
One workaround could be as follows:
- open DB
- get its lenght (with "L DBLG" instruction)
- divide it by size of the array (but this must be known in advance)
 
I read the thread that you showed me, but it's not exactly what I need. There is only one DB, you and S7Guy if you want to calculate the lenght of a UDT give always the instruction by the name of the DB and the name of an array( DBNAME.ARRAYNAME[1]). The problem is that I don't want do give a name of a DB. The best way would be to do something like this: DB[db_nr].array_of_udts[udt_nr]. Thus I could easily move from objects of one DB to objects of an another DB, only by changing a db_nr and udt_nr.
And of cours I don't have SCL:-((
 
Last edited:

Similar Topics

Hi, I have a problem with addresses of a DB. I have two DBs. In one(DB 10) I keep the address of the element from the second one(DB1000). What I...
Replies
3
Views
4,820
Howdy folks, I am an Allen Bradley guy currently living in an Emerson world. Working with Rx3i on PacSystems Machine Edition v. 9.6? i think...
Replies
3
Views
620
Hey, I'm trying to do the following, I have some experience with Citect but can't seem to figure this out. I/O Tag: BoxPos1_ProdNum (Data Type...
Replies
0
Views
578
Hello, I'm very new to programming with absolutely zero schooling in this field and pretty hands off training in my new role, it's been fun...
Replies
4
Views
668
Hi, I have this code: LAR1 P##structy L 0 T LW [AR1,P#0.0] which resets all the bits in this struct called structy...
Replies
1
Views
641
Back
Top Bottom