Sub Main()
	 Event("ADD", "MES.AlarmAsMessage", "ALL>S", "ManageAlarm", "", "TakeIntoAccountThisNewAlarm");
End Sub

Sub TakeIntoAccountThisNewAlarm()
	If (CmpString(@MES.AlarmAsMessage, "") == 0) Then
		'Do Nothing
	Else
		'New alarm to trigger
		Variable("SETTATT", "MES.Alarm", 3, @MES.AlarmAsMessage);
		@MES.Alarm = 1;
		'Reset to fast is not Ok
		'@MES.Alarm = 0;
	End If
End Sub

Sub RandomAlarm()
'Error closing operation XXXX for the Production Order YYYYYYYYY
Dim XXXX as Integer;
Dim YYYYYYYYY as Integer;
Dim NewAlarmMessage as Str;

	'Reset alarm if on
	If (@MES.Alarm) Then
		@MES.Alarm = 0;	
	End If

	XXXX = Irand();
	YYYYYYYYY = Irand();
	NewAlarmMessage = AddString("Error closing operation ", Toc(XXXX), " for the Production Order ", Toc(YYYYYYYYY));
	@MES.AlarmAsMessage = NewAlarmMessage;
End Sub

