Swapped Delay for millis but can't get program to run properly

I have a program that sweeps through frequencies 1hz to 6 hz . I can change duty cycle and number of pulses at each frequency. I was using the delay function ,but realised that I can’t add an indipendant signal with the delays in place so I swapped to millis. Unfortunately with the millis now in place I can not get the progam to run properly.
I’m sure it’s a simple fix for an experienced programmer and so was hoping that someone may be able to point out my error

uint8_t freq_Hz[6] ={1,2,3,4,5,6};// Set up an array for the 6 frequencies 
uint8_t pulses =25;              // Number of pulses per frequecncy
uint8_t  duty =50;                // Sets Duty cycle
unsigned long period_ms;

unsigned long currentMillis;
unsigned long startMillis;
unsigned long OnTime =0;
unsigned long Period_ms;
unsigned long Toff =0;
 int out_pin=5;
 int out_pin1 =2;
 int Led1=8;
 int Led2=9;
void setup() {
  // put your setup code here, to run once:
{
  pinMode(out_pin,OUTPUT);
  pinMode(out_pin1, OUTPUT);
  pinMode(Led1,OUTPUT);
  pinMode(Led2,OUTPUT);
}
}
void loop()

  // put your main code here, to run repeatedly:
  {
  for (uint8_t i=0;i<6;++i){                      //Cycle through the 6 elements of freq_hz array
  period_ms =1000/freq_Hz[i];                     // Calculate the period in ms of freq_hz
  OnTime = (period_ms*duty)/100;                 // Calculate from % duty cycle ON Time in ms
  Toff=(100-duty)*1000/freq_Hz[i]/100;            // Calculates off time
for(uint8_t j=0; j<pulses;++j){   
                                 // loops frequency x pulses at each frequency
 currentMillis=millis();                                
 if (currentMillis -startMillis<= OnTime)   
 {                              
digitalWrite (out_pin,HIGH);
digitalWrite (out_pin1,HIGH);
digitalWrite (Led1,HIGH);
digitalWrite (Led2,HIGH);
 }
 else if (currentMillis-startMillis>OnTime && currentMillis- startMillis < period_ms)
{
digitalWrite(out_pin,LOW);
digitalWrite(out_pin1,LOW);
digitalWrite(Led1,LOW);
digitalWrite(Led2,LOW);
}
else if (currentMillis-startMillis >=period_ms) // reset timer 
startMillis=currentMillis;

}
  }
  }
unsigned long startMillis;

Start of what? Using a name that makes sense would go a long way to understanding what it happening in your program.

void setup() {
  // put your setup code here, to run once:
{
  pinMode(out_pin,OUTPUT);
  pinMode(out_pin1, OUTPUT);
  pinMode(Led1,OUTPUT);
  pinMode(Led2,OUTPUT);
}
}

{What's} {with} {the} {useless} {curly} {braces} {?}

I gave up following your code. It is too piss-poorly indented for me to waste time deciphering.

The Arduino team made it REALLY easy to keep your code properly indented, providing the Auto Format item in the Tools menu. Use it!

startMillis is declared but not initialised in setup i.e. it has no value when your loop starts comparing.

As Paul says, look at your code again and clean it up using the auto format option in the ide.

I can not get the progam to run properly.

A better description of the problem would help to diagnose what is wrong

was hoping that someone may be able to point out my error

for (uint8_t i=0;i<6;++i)

for(uint8_t j=0; j<pulses;++j)

These two for() loops should be changed to conditionals with if(index <= number) and the index incremented only after the intended action is complete. The code is executing the for() loops very quickly before any of the millis() based actions can occur.

hi Thanks for that, could you possibly give me an example?

I’ve indented the code and replaced the delay times with millis

uint8_t freq_Hz[6] = {1, 2, 3, 4, 5, 6}; // Set up an array for the 6 frequencies
uint8_t pulses = 25;             // Number of pulses per frequecncy
uint8_t  duty = 10;               // Sets Duty cycle
unsigned long period_ms;
unsigned long OnTime = 0;
unsigned long offTime = 0;
unsigned long previousMillis = 0;
//unsigned long currentMillis;
int out_pin = 5;
int out_pin1 = 2;
int Led1 = 8;
int Led2 = 9;
void setup() {
  // put your setup code here, to run once:
  {
    pinMode(out_pin, OUTPUT);
    pinMode(out_pin1, OUTPUT);
    pinMode(Led1, OUTPUT);
    pinMode(Led2, OUTPUT);

  }

}
void loop()

// put your main code here, to run repeatedly:
{

  unsigned currentMillis = millis();

 for (uint8_t i = 0; i < 6; ++i) {    //Cycle through the 6 elements of freq_hz array


    period_ms = 1000 / freq_Hz[i];                  // Calculate the period in ms of freq_hz
    OnTime = (period_ms * duty) / 100;             // Calculate from % duty cycle ON Time in ms

    for (uint8_t j = 0; j < pulses; ++j) { // loops frequency x pulses at each frequency


      unsigned long currentMillis = millis();// get current time
      if (currentMillis - previousMillis <= OnTime)//test whether the on period has elapsed
      {

        digitalWrite (out_pin, HIGH);
        digitalWrite (out_pin1, HIGH);
        digitalWrite (Led1, HIGH);
        digitalWrite (Led2, HIGH);

      }
      else if (currentMillis - previousMillis >= OnTime && currentMillis - previousMillis < period_ms )// test whether the off time has elapsed
        //delay(OnTime);
      {

        digitalWrite(out_pin, LOW);
        digitalWrite(out_pin1, LOW);
        digitalWrite(Led1, LOW);
        digitalWrite(Led2, LOW);
        //delay(period_ms - OnTime);
      }
      else if (currentMillis - previousMillis >= period_ms - OnTime)
        previousMillis = currentMillis;
    }
  }
}
  unsigned currentMillis = millis();

Interesting ...