Difficulty Changing Duration When Button Not Pressed

Hello everyone and thank you for helping out a newbie trying to learn about time-dependent events. I have mostly graduated beyond the delay function but I'm running into a confusing issue with my latest lesson.

My sketch detects if 10 minutes or greater has elapsed since the last button press. I want to change a timing duration called "programLength" if the button is neglected for more than 10 minutes. The programLength starts out randomly set between 30 and 45 minutes before ringing a bell to signal the end, but it needs to switch to 60 minutes before ringing the bell if the button is ever neglected for 10 minutes or more.

My code successfully detects if the button is neglected and cancels the original 30-45 duration, but for some reason will not replace it with the desired 60-minute duration. In other words, if the button is neglected for more than 10 minutes, the bell does not ring at 60 minutes like it's supposed to. The program keeps going and the bell never rings. (However, if the button is not neglected, the bell rings on schedule at the expiration of the original 30-45 minute duration.)

I would really appreciate your pointers on where I went wrong getting the 60-minute duration to take hold. I'm at a loss. Thanks, guys!

// pin vars
int bellPin = 7;
int buttonPin = 2;
int buttonPower = 4;

// timing vars
unsigned long programLength = millis();
unsigned long lastButtonTime = millis();
long randomNumber1;

// state vars
int buttonPressedState = 0;
boolean buttonNeglected = false;

void setup() 
  pinMode(bellPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(buttonPower, OUTPUT);
  digitalWrite(buttonPower, HIGH);
  randomNumber1 = (random(30, 45));
  programLength = randomNumber1 * 1000 * 60;  //set an initial program length of between 30-45 minutes

void loop() 
//detect button press and record time last button press was detected
 buttonPressedState = digitalRead(buttonPin);
 if (buttonPressedState == LOW) {
  Serial.println("Button press detected");
  lastButtonTime = millis();
 //reset program length to 60 minutes if 10 minutes are allowed to elapse since last button press
 if (((millis() - lastButtonTime) > (1000 * 10 * 60)) && buttonNeglected == false) {
  programLength = 60 * 1000 * 60;
  buttonNeglected = true;
  Serial.println("Program length reset to 60 minutes due to 10 minutes of button neglect");

//ring the bell at the program's end
if (millis() > programLength) {
    Serial.println("The bell will keep ringing at 5 second intervals to signal the program's end.");
    delay(5000); //delay 15 seconds;
unsigned long programLength = millis();

That is a strange initial value. You really need a comment to explain why that value is used.

  randomNumber1 = (random(30, 45));

(What's) (with) (the) (useless) (parentheses) (?)

 if (((millis() - lastButtonTime) > (1000 * 10 * 60)) && buttonNeglected == false) {

1000 * 10 * 60 will NOT fit in an int.

  programLength = 60 * 1000 * 60;

60 * 1000 * 60 will not fit in an int.

if (millis() > programLength) {

Why; is; there; a; semicolon; there;?

    programLength = 60 * 1000 * 60;

Start by printing programLength. What do you see ?

Unless forced to do otherwise the calculation will be done as if all of the numbers are ints and the result will be an int. You can force the result to be an unsigned long by making at least one of the numbers an unsigned long like this

   programLength = 60UL * 1000 * 60;

I suspect that there may be other problems with the code but I am short of time to look at the moment.

if (millis() > programLength) {

I think you meant...

if (millis()-programStartTime > programLength) {

But you didn't record the start of the program did you?

This section seems to lock into continuous ringing until it is turned off? You don't want to have a 'reset' or 'restart' button?

When I printed programLength after the button neglect condition was met, it returned an enormous number seemingly out of nowhere. The bell would have eventually rung in several weeks! When I followed UKHeliBob's suggestion to change 1000 to 1000UL in the multiplication, it solved the problem and programLength was reset to 60 minutes upon button neglect.

Thank you for your helpful pointers!