I can probably help you, but I need a bit of clarification on what you mean by "effient".
If by efficient, you are worried about how much time it takes for the PLC to execute the code, there are ways to minimize the number of tests made. This is sometimes called "common subexpression elimination". I doubt that the TBASIC compiler is smart enough to do this for you. I notice that the subexpression, "D=0 AND DM[2] = DM[41]” is repeated 8 times. You could made this test once. Some thing like this:
dm[430] = 0
if d=0 and dm[2]=dm[41] and dm[647]>=1 and dm[647]<=8
dm[430]=dm[647]
if dm[647] = 1
dm[20] = a
elif dm[647] = 2
dm[20] = f
elif dm[647] = 3
dm[20] = b
elif dm[647] = 4
dm[20] = g
elif dm[647] = 5
dm[20] = c
elif dm[647] = 6
dm[20] = e
elif dm[647] = 7
dm[20] = h
else
dm[20] = i
endif
endif
[/font][/color]
The code could be simplified more if there was a pattern to which variable is assigned to dm[647]. This whole section of code could be a simple if statement with two assignments. If the values were stored in an array such as dm[1001] through dm[1008], then the code could be further simplified:
dm[430]=0
if d=0 and dm[2]=dm[41] and dm[647]>=1 and dm[647]<=8
dm[430]=dm[647]
dm[20] = dm[1000+dm[647]]]
endif
[/font][/color]
If by efficient you want code that was less prone to errors and is easier to write and maintain. I have suggestions about how to organize your data usage and how to use the #define mechanism.
These suggestions are a bit too complicated to do in a reply to a question. If you email me and send me your PLC Program, I could take a whack at re-write.
A question that I need to ask is about your programming experience. If you are a real novice, then my approach will not help. If you are comfortable with modern programming languages that support data structures and arrays of data structures, then you will understand the approach that I take.
Gary D*ickinson. My email address is in my profile. I cannot put it in the body of the email as the Malaysian forum sensors do not approve of my family name.