search for a value in a DB (S7)

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Anyone knows how to search in a file...

For example:

I want to find empty spaces in a DB by searching after zero values...


Can I do it with a for next loop in SCL ...

Hows ?
 
Here's one example:

Code:
FUNCTION FC123:INT //search DB for first zero doubleint. Returns -1 if none found
VAR_INPUT
SearchDB:word;
end_var
VAR_TEMP
index: INT;
wdbLength:WORD;
bWriteProtect:BOOL;
iSFC24Return:INT;
END_VAR
BEGIN
iSFC24Return:=SFC24(DB_NUMBER := SearchDB
		,DB_LENGTH := wdbLength
		,WRITE_PROT := bWriteProtect
		);
FC123:=-1;		//default none found
FOR index:=0 TO (WORD_TO_INT(wdbLength)/4)-1 DO 
IF WORD_TO_BLOCK_DB(SearchDB).DD[index*4] = 0 THEN 
	FC123:=index*4; //returns byte address of doubleint = 0
	EXIT;
END_IF;	
END_FOR;
END_FUNCTION;
 
Last edited:
Alternatively I think there's also a ready-written FC in the TI->S7 Library of STEP7 to do this. I'm not at a PC with STEP7 so I can't check the number right now, but have a dig around in there.


Ken
 
I'm prepared to bet that L D[AR2 ...]'s (you've got to get a shorter name!) code is probably shorter, neater, more stable, and easier to understand than FC86. No doubt FC86 will provide the ability to search for any data type in any data block subject to 'n' different criteria with feedback and error codes to cater for 'n^2' different circumstances, but sometimes you just want to find an empty space ...
 

Similar Topics

Hello all, Some of you may be familiar with the RAM searching program for Windows computers, Cheat Engine. You can search RAM directly for...
Replies
0
Views
753
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,445
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,354
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
259
I have an InTouch HMI that has PID parameters. I need to find what the PID values were in the past. I have backups from the past, but none...
Replies
48
Views
5,607
Back
Top Bottom