EEPROM.write sometimes works, sometimes not

Hello,

I have got a strange Problem. Sometimes the Value is written in the EEPROM, sometimes not. I know its not the best way how Im doing.

Any ideas?

  if (encoderPos != encoderPosMem)
  {
   lastTimeR = millis();
   MemWrite = 1;
   Trigger = 1;
   encoderPosMem = encoderPos;
  } 


  if (millis()-lastTimeR > WriteDelay && Trigger == 1)
  {
    byte encoderPosMem2 = EEPROM.read(1);
    if (encoderPosMem2 != encoderPosMem)
    {
    EEPROM.write(1, encoderPosMem);
    if (encoderPos == encoderPosMem)
      {
        MemWrite = 2;
        Trigger = 2;
      }
    }
  }

Any ideas?

Without seeing the types? No.

Post ALL of your code.

Which types do you mean? This is all code.

This is all code.

Nope. No setup, no loop.

This is all code.

How can it be? The variables are not typed anywhere. This is NOT PHP. Variables MUST be typed. Plus what AWOL said.