Variable Reverts after Serial Update Stops

Hi,

I have simple program that prints some data to the serial port and allows one variable to be altered via serial Vmax. When I update the variable with a visual basic program (which also lets me view the serial stream), the variable changes. I can see in the serial stream that it is changed to the new value.

When I disconnect from the serial port, the value returns the value at which it was initialized. In serial monitor, Vmax returns to 0.4 when disconnected. It appears that if this program reads nothing at the serial port, 0.400 is the assigned value of Vmax. I would expect it to stay at the last value it was assigned. Can anyone see why this is happening?

String inData;
int Vmaxint;
double Vmax=0.4;

void setup() 
{  
Serial.begin(9600);
randomSeed(analogRead(0));    
} 
void loop() {
double randnum=.523;
  for(int i = 1; i<31;i++) {
    randnum = random(1,1000);
    randnum = randnum / 10000;
    //Serial.print(randnum,3);
     Serial.write(" Cell ");
     Serial.print(i);
     Serial.write(" Voltage=");
          Serial.print(randnum,3);
           Serial.write("\n");
            
  }
          Serial.write("Vmax:");
          Serial.print(Vmax,3);
          Serial.write("\n");
              delay(1000);
  Serial.write("----------------------------------------\n");
    delay(1000);
 if(Serial.available()>0)
 {  
   while (Serial.available())
    {
    char received = Serial.read();
    inData += received;  
    }
    Vmaxint= inData.toInt();
    Vmax = double(Vmaxint);
    Vmax = Vmax/1000;
    inData = " ";

 }
  }

When you connect and disconnect the USB, the Arduino is restarted. All SRAM data is lost, and will be reset to the bootup default.

Thank You. I verified that this is the issue. If I connect using a home-made visual basic port monitor, and I disable .DtrEnable and .RtsEnable on the reader, the value is retained when I connect and disconnect from the serial port as long as power is not interrupted.

JSPCT:
Thank You. I verified that this is the issue. If I connect using a home-made visual basic port monitor, and I disable .DtrEnable and .RtsEnable on the reader, the value is retained when I connect and disconnect from the serial port as long as power is not interrupted.

If you store the value in EEPROM, you can read the value there in setup(), s even power changes/resets do not result in loss.