Cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulty Structuring IF Statement

Hi All,

 

I am having structuring some nested IF statements. It reads the first IF statement and if it doesn't satisfy it, it jumps straight to the end without looking at the rest of the 'ElseIf' statements. I think this has to do with where the 'End's should be, could anyone please advice if I have put them in the wrong place? Thank you!

 

(attribute: string; oldValue: any)
is
	a : integer;
	b : integer;
	c : integer;
	d : integer;
	e : integer;
	f : integer;
do
	if CurrentShiftRC = "MTD" then
		
		a := RC.cont.RemainingProcTime;
		b := BuildRate[3,4];
		c := a*100;
		d := c/b;
		e := BuildRate[1,4]*d;
		f := e/100;
		
			if RC.cont.Part = "RCL" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCL.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[1,4];
			
			elseif RC.cont.Part = "RCM" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCM.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[1,4];
	
			elseif RC.cont.Part = "RCS" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCS.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[1,4];
			end;
			
	elseif CurrentShiftRC = "MTB" then
		
		a := RC.cont.RemainingProcTime;
		b := BuildRate[1,4];
		c := a*100;
		d := c/b;
		e := BuildRate[2,4]*d;
		f := e/100;
		
			if RC.cont.Part = "RCL" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCL.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[2,4];
			
			elseif RC.cont.Part = "RCM" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCM.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[2,4];
			
			elseif RC.cont.Part = "RCS" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCS.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[2,4];
		end;
			
	elseif CurrentShiftRC = "MTN" then
		
		a := RC.cont.RemainingProcTime;
		b := BuildRate[2,4];
		c := a*100;
		d := c/b;
		e := BuildRate[3,4]*d;
		f := e/100;
		
			if RC.cont.Part = "RCL" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCL.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[3,4];
			
			elseif RC.cont.Part = "RCM" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCM.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[3,4];
			
			elseif RC.cont.Part = "RCS" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCS.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[3,4];
		end;
			
	elseif CurrentShiftRC = "FRD" then
		
		a := RC.cont.RemainingProcTime;
		b := BuildRate[3,4];
		c := a*100;
		d := c/b;
		e := BuildRate[4,4]*d;
		f := e/100;
		
			if RC.cont.Part = "RCL" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCL.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[4,4];
			
			elseif RC.cont.Part = "RCM" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCM.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[4,4];
			
			elseif RC.cont.Part = "RCS" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCS.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[4,4];
		end;
			
	elseif CurrentShiftRC = "FRB" then
		
		a := RC.cont.RemainingProcTime;
		b := BuildRate[4,4];
		c := a*100;
		d := c/b;
		e := BuildRate[5,4]*d;
		f := e/100;
		
			if RC.cont.Part = "RCL" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCL.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[5,4];
			
			elseif RC.cont.Part = "RCM" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCM.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[5,4];
			
			elseif RC.cont.Part = "RCS" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCS.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[5,4];
		end;
			
	elseif CurrentShiftRC = "FRN" then
		
		a := RC.cont.RemainingProcTime;
		b := BuildRate[5,4];
		c := a*100;
		d := c/b;
		e := BuildRate[6,4]*d;
		f := e/100;
		
			if RC.cont.Part = "RCL" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCL.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[6,4];
			
			elseif RC.cont.Part = "RCM" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCM.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[6,4];
			
			elseif RC.cont.Part = "RCS" then
			RC.cont.move(DF3);
			RC.ProcTime := f;
			.MUs.RCS.create(RCF);
			RCF.cont.move(RC);
			waituntil RC.empty = true prio 1;
			RC.ProcTime := BuildRate[6,4];
		end;
	end;
end;
4 REPLIES

Re: Difficulty Structuring IF Statement

Not sure if it helps, or why it happens, but in the second IF statement, it seems to have an issue with the string data type, as if I remove the quote marks the code seems to structure correctly.

Re: Difficulty Structuring IF Statement

Siemens Phenom Siemens Phenom
Siemens Phenom

Hello Nathan,

 

it is difficult to tell why this behavior occurs without having the corresponding model at hand. Of what data type is your "Part" attribute? This could make also a difference, if it is not a string then your evaluation in the if-statement will always evaluate to false and thus skip the whole branch altogether.

Kind regards,

Igor
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution


Re: Difficulty Structuring IF Statement

Hi Igor,

 

Yes I understand, I wish I could share but the model has sensitive data.

 

The data type for 'Part' is string so shouldn't skip as you mentioned. As an interim solution I have split the method down as to not have nested IF's which thankfully now works, but still confused as to why the code I posted reads the first line, and it if doesn't satisfy the scenario, skips to the very end without considering the 'elseifs'. Oh well!

Re: Difficulty Structuring IF Statement

Phenom
Phenom

Looks like a observer method

 

(with a lot of waituntil statements).

 

If that's case what attribute are you observing ?

 

Have you yet set a breakpoint to verify the values

 

of "CurrentShiftRC" and "RC.cont.Part" ?