Search array Siemens S7-1500

BNA

Member
Join Date
Sep 2003
Location
Give
Posts
117
Hi

I am stuck in trying to get my code search an array and retur an index number.

So, I have an array from 0 to 254 created from an UDT where I have a timer SP, a Timer ET, a scale of the timer and a manufactor item number like this.

Timer[0]
Timer_SP (DINT)
Timer_ET (DINT)
Scale (INT)
Item_NO (DINT)

Timer[1] And so on

What I am trying, is to make a small piece of SCL code that allows me to search my array for the item number and return the place number i my array (The value in []).

This is what I got so far:

FOR #Index := 0 TO 255 DO;
IF Array_DB.TIMER[#Index].Item_NO = #Value_to Search
THEN EXIT;
END_IF;
END_FOR;

Any suggestions

Best Regards
Brian
 
Hi Garry

Thank you for your reply, but it is not excactly what I am looking for, it is the other way around. I want to search a specific number i my array and return the matching number, if that makes sense.

So if I for example search for item_no XXXX and find a match, it should retur for example Timer[0]

/Brian
 
Hi L D[AR2,P#0.0]

Thank you for the reply and thanks for testing.

It is a bit strange it is not working here, but at least I know the code is working so there must be a reference error somewhere.

I will start a search :)

/Brian
 
Hi L D[AR2,P#0.0]

Thank you for the reply and thanks for testing.

It is a bit strange it is not working here, but at least I know the code is working so there must be a reference error somewhere.

I will start a search :)

/Brian

Problem solved: I had put 0 TO 255 in my array but the actual array were 0 TO 254
 
Problem solved: I had put 0 TO 255 in my array but the actual array were 0 TO 254


I'm always amazed at the places those sorts of errors can sneak in.


I was upgrading some code a few months back where I thought it wasn't starting because of all these array bound errors I was finding every time i ran the code. It turns out that I was missing some config value that prevented the loops from ever getting high enough to notice that they didn't match, so the code had been "wrong" for the last 10 years at least, but ran just fine.
 

Similar Topics

Hi I new to ST programming and I am trying to figure out how I can search an array for an value (3). I want TEST to go high if eg trayArray[6] =...
Replies
10
Views
2,431
Hi guys, I have a small project that I am working on, I have this station that a unit enters, an RFID reads the unit's serial ID then it starts...
Replies
16
Views
3,345
A customer is asking if I can do a check on his batch numbers and reject a batch from starting if the check fails. The setup is as follows: I have...
Replies
5
Views
1,570
when you have an array of 100 DINT's... And you enter in a wincc flex I/O field a DINT value to search for. How can you do that and know the...
Replies
3
Views
2,348
Searching edit zones within all routines and other criteria still says no results found, yet I still have the "edits present" indicator at the...
Replies
6
Views
248
Back
Top Bottom