Variable Delay: the big problem

Hi everybody!

I'm getting an SMS on a GSM module, and sending to the serial monitor.
The SMS is basically: "# vermelho45amarelo11verde37." Each number (45, 11, 37)*1000 will be used as delay to turn on 3 LEDS.
Analyzing the Serial Monitor the values are correct.
But when i use a delay like delay(vm), where vm=45000, the LED doesn't works. If I change delay(vm) to delay(45000) it's works normally.
Can someone help me please?!?!

Here goes my code:

int ledverm = 39;
int ledamar = 41;
int ledverd = 43;
long int vm;
long int vm1;
long int vm2;
long int am;
long int am1;
long int am2;
long int vd;
long int vd1;
long int vd2;
String strvm1;
String strvm2;
String stram1;
String stram2;
String strvd1;
String strvd2;

void setup()
{
  Serial1.begin(19200);
  Serial.begin(19200);
  pinMode(ledverm, OUTPUT);
  pinMode(ledamar, OUTPUT);
  pinMode(ledverd, OUTPUT);
  // Configure para receber mensagens de outros dispositivos
  // Entre as equipes dar tempo para processá-los
  Serial1.print("AT+CMGF=1\r");
  delay(300);
  Serial1.print("AT+IFC=1, 1\r");
  delay(300);
  Serial1.print("AT+CPBS=\"SM\"\r");
  delay(300);
  Serial1.print("AT+CNMI=1,2,2,1,0\r");
  delay(500);
  Serial1.print("AT+CMGD=1,4");
  delay(500);
  Serial.print("AT+CMGF=1\r");
  delay(300);
  Serial.print("AT+IFC=1, 1\r");
  delay(300);
  Serial.print("AT+CPBS=\"SM\"\r");
  delay(300);
  Serial.print("AT+CNMI=1,2,2,1,0\r");
  delay(500);
  Serial.print("AT+CMGD=1,4\r");
  delay(500);
}

String currStr = "";
// A variável tem o valor True, se a linha atual é a mensagem
boolean isStringMessage = false;

void loop()
{

  if (!Serial1.available())
    return;

  char currSymb = Serial1.read(); delay(2);   
  if ('\r' == currSymb) {
    if (isStringMessage) {

      strvm1 = currStr.substring(9,10);
     long  int testevm1 = strvm1.toInt();
      char charvm1[strvm1.length()+1];
      strvm1.toCharArray(charvm1, sizeof(charvm1));
    long   int vm1 = atoi(charvm1);
      Serial.print("\rstrvm1=");Serial.print(strvm1);
      Serial.print("\rvm1=");Serial.print(vm1);
      Serial.print("\rtestevm1=");Serial.print(testevm1);
      
      strvm2 = currStr.substring(10,11);
      int testevm2 = strvm2.toInt();
      char charvm2[strvm2.length()+1];
      strvm2.toCharArray(charvm2, sizeof(charvm2));
      int vm2 = atoi(charvm2);
      Serial.print("\rstrvm2=");Serial.print(strvm2);
      Serial.print("\rvm2=");Serial.print(vm2);
      Serial.print("\rtestevm2=");Serial.print(testevm2);

      stram1 = currStr.substring(18,19);
     long  int testeam1 = stram1.toInt();
      char charam1[stram1.length()+1];
      stram1.toCharArray(charam1, sizeof(charam1));
     long  int am1 = atoi(charam1);
      Serial.print("\rstram1=");Serial.print(stram1);
      Serial.print("\ram1=");Serial.print(am1);
      Serial.print("\rtesteam1=");Serial.print(testeam1);

      stram2 = currStr.substring(19,20);
     long  int testeam2 = stram2.toInt();
      char charam2[stram2.length()+1];
      stram2.toCharArray(charam2, sizeof(charam2));
    long   int am2 = atoi(charam2);
      Serial.print("\rstram2=");Serial.print(stram2);
      Serial.print("\ram2=");Serial.print(am2);
      Serial.print("\rtesteam2=");Serial.print(testeam2);

      strvd1 = currStr.substring(25,26);
     long  int testevd1 = strvd1.toInt();
      char charvd1[strvd1.length()+1];
      strvd1.toCharArray(charvd1, sizeof(charvd1));
    long   int vd1 = atoi(charvd1);
      Serial.print("\rstrvd1=");Serial.print(strvd1);
      Serial.print("\rvd1=");Serial.print(vd1);
      Serial.print("\rtestevd1=");Serial.print(testevd1);

      strvd2 = currStr.substring(26,27);
     long  int testevd2 = strvd2.toInt();  
      char charvd2[strvd2.length()+1];
      strvd2.toCharArray(charvd2, sizeof(charvd2));
     long  int vd2 = atoi(charvd2);
      Serial.print("\rstrvd2=");Serial.print(strvd2);
      Serial.print("\rvd2=");Serial.print(vd2);   
      Serial.print("\rtestevd2=");Serial.print(testevd2);   
      
    long   int vms = (vm1+vm2);      Serial.print("\rvms=");Serial.print(vms);      
     long  int ams = (am1+am2);      Serial.print("\rams=");Serial.print(ams);      
     long  int vds = (vd1+vd2);      Serial.print("\rvds=");Serial.print(vds);      
     long  int vm = (vms*1000);      Serial.print("\rvm=");Serial.print(vm);      
     long  int am = (ams*1000);      Serial.print("\ram=");Serial.print(am);      
     long  int vd = (vds*1000);      Serial.print("\rvd=");Serial.print(vd);      

   long    int vmteste=(testevm1+testevm2)*1000;      Serial.print("\rvmteste=");Serial.print(vmteste);      
     long  int amteste=(testeam1+testeam2)*1000;      Serial.print("\ramteste=");Serial.print(amteste);      
     long  int vdteste=(testevd1+testevd2)*1000;      Serial.print("\rvdteste=");Serial.print(vdteste);      
      
      
      isStringMessage = false;

      semaforo();
    } 
    else {
      if (currStr.startsWith("+CMT")) {
        // Se a linha atual começa com um "+ CMT",
        // A linha seguinte é a mensagem
        isStringMessage = true;
      }
    }
    currStr = "";
  } 
  else if ('\n' != currSymb) {
    currStr += String(currSymb);
    char carray[currStr.length()+1];
    currStr.toCharArray(carray, sizeof(carray));

  }
}

void semaforo(){

  digitalWrite(ledverm, HIGH);
  digitalWrite(ledamar, LOW);
  digitalWrite(ledverd, LOW);
  delay(vm);

  digitalWrite(ledverm, LOW);
  digitalWrite(ledamar, HIGH);
  digitalWrite(ledverd, LOW);
  delay(am);

  digitalWrite(ledverm, LOW);
  digitalWrite(ledamar, LOW);
  digitalWrite(ledverd, HIGH);
  delay(vd);
}

Did you try declaring your delay as an 'unsigned long' type?

You are declaring variables like vm twice - did you mean to?

[ to be more precise you are declaring two variables vm, one global used by semaforo(), and one
local to loop() which you print to the Serial stream. The variables are completely distinct.

You re-declare vm,am and vd inside of your loop function. When you write:

int vm;

That allocates some memory to your variable called vm. In your loop function if you declare it again it creates a new local variable with the same name, when the function returns that variable is discarded and vm takes the value of the original global variable, which is 0.
Effectively in your loop where you have things like:

     long   int vms = (vm1+vm2);      Serial.print("\rvms=");Serial.print(vms);      
     long  int ams = (am1+am2);      Serial.print("\rams=");Serial.print(ams);      
     long  int vds = (vd1+vd2);      Serial.print("\rvds=");Serial.print(vds);      
     long  int vm = (vms*1000);      Serial.print("\rvm=");Serial.print(vm);      
     long  int am = (ams*1000);      Serial.print("\ram=");Serial.print(am);      
     long  int vd = (vds*1000);      Serial.print("\rvd=");Serial.print(vd);

Change it to:

     vms = (vm1+vm2);      Serial.print("\rvms=");Serial.print(vms);      
     ams = (am1+am2);      Serial.print("\rams=");Serial.print(ams);      
     vds = (vd1+vd2);      Serial.print("\rvds=");Serial.print(vds);      
     vm = (vms*1000);      Serial.print("\rvm=");Serial.print(vm);      
     am = (ams*1000);      Serial.print("\ram=");Serial.print(am);      
     vd = (vds*1000);      Serial.print("\rvd=");Serial.print(vd);