Middle String (MID)
The MID instruction copies a specified number of ASCII characters from a string and stores them in another string.
The MID instruction copies a group of characters from the Source and places the result in the Destination.
- The Start position and Quantity define the characters to copy.
- Unless the Source and the Destination are the same tag, the Source remains unchanged.
Available Languages
Ladder Diagram
FactoryTalk Design Studio
DSL - Ladder DiagramMID(Source,Qty,Start,Dest);
Operands
There are data conversion rules for mixed data types within an instruction. See Data Conversion.
Ladder Diagram
Operand | Type | Format | Description | Notes |
---|---|---|---|---|
Source | ANY_STRING | Tag | The string to copy characters from | String types are:
|
Quantity | SINT
INT
DINT | Immediate
tag | The number of characters to copy | The Start plus the Quantity must be less than or equal to the length size of the Source plus 1. |
Start | SINT
INT
DINT | Immediate
tag | The position of the first character to copy | Enter a number between 1 and the DATA size of the Source. |
Destination | ANY_STRING | Tag | The string to copy the characters to |
Affects Math Status Flags
No
Major/Minor Faults
A minor fault will occur if: | Fault Type | Fault Code |
---|---|---|
The LEN value of the Source string tag is greater than the DATA size of the Source string tag. | 4 | 51 |
The length of output string is larger than the DATA size of the destination string tag. | 4 | 52 |
The Start or Quantity value is invalid. | 4 | 56 |
Execution
Ladder Diagram
Condition | Ladder Diagram Action |
---|---|
Prescan | N/A |
Rung-condition-in is false | N/A |
Rung-condition-in is true | The instruction executes. |
Postscan | N/A |
Example
In the baggage handling conveyor of an airport, each bag gets a bar code. Characters 9 through 17 of the bar code are the flight number and destination airport of the bag. After the bar code is read (bag_read.EM is on), the MID instruction copies the flight number and destination airport to the bag_flt_and_dest string. Subsequent rungs use bag_flt_and_dest to determine where to route the bag.
Ladder Diagram
Provide Feedback