Entering numbers at the Serial Monitor

Hello All,
I'm using a Uno + XBee Series 1 + LCD to mirror the reading at a gas meter - this is mainly to do with the difficulty in reading the thing where it is sited. As a real novice here, I have managed to get everything going to the point where the Hall sensor at the meter picks up each dial rotation and adds it to the LCD display in the house. To get real readings displayed, I need to input a nine digit number which is the "offset" to which the incoming pulses are added.

I was playing around with some published sketches (thank you) with the code below.

int incomingByte = 0;   // for incoming serial data
String inString = "";    // string to hold input

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
  Serial.print ("enter data at command line and check that set to NEWLINE");
  Serial.print("\n");//needs this to display "value" and "string" - if omitted, displays "string" only first time round
}

void loop() {
            // put your main code here, to run repeatedly: 
             // send data only when you receive data:
            if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();
                 if (isDigit(incomingByte)) {
      // convert the incoming byte to a char 
      // and add it to the string:
      inString += (char)incomingByte; 
    }
                 if (incomingByte == '\n') {
      Serial.print("Value:");
      Serial.println(inString.toInt()*2);
      Serial.print("String: ");
      Serial.println(inString);
      // clear the string for new input:
      inString = ""; 
    }

              
        }
}

I have only changed some of the text messages and added one calculation (*2).

If I enter 999999999 (i.e.9 digits), everything is OK - if a tenth digit is added, it overflows.

Can someone tell me why it happens, and what is the significance of the "overflow" number that comes up on the Serial Monitor?

Thanks

int incomingByte = 0; // for incoming serial data

Why? If the name implies byte, why is the type not byte? Use a name that IS what it implies.

                 if (isDigit(incomingByte)) {

isDigit() expects a char.

      // convert the incoming byte to a char 
      // and add it to the string:
      inString += (char)incomingByte;

Another clue as to the correct type for the variable.

If I enter 999999999 (i.e.9 digits), everything is OK - if a tenth digit is added, it overflows.

Have you looked at the documentation for the toInt() method? Despite the stupid name, it does not return an int. Does the 10 character value you are trying to enter actually fit in a variable of the type that toInt() actually returns?

There IS a reason for the reference page. You ARE expected to use it.

Hello Paul,
Thanks for the reply - you must be up early - it's 16:48 GMT here in UK.
I'm afraid that I'm at the stage in life where most folks prefer to do crosswords, but I'm always ready for a challenge and coping with Zigbee and Arduino plus the hardware is fairly demanding starting from zero. I'll take a look at all the things you have suggested and toInt() is a new one on me. I have to glean knowledge from wherever I can and I do make use of all the resources, but now and again you need a little guidance. I definitely WILL have a look at what reference has to say, but this is one old dog trying to learn new tricks.
Thanks again

but this is one old dog trying to learn new tricks.

I'm pretty sure you borrowed that code from somewhere. It irritates me how many times I see

int incomingByte;

That's nearly as irritating as

byte myInt;
float myChar;
int myFloat;

etc. that I've seen.

If you are going to, unnecessarily, use a type name in a variable name, the type name needs to match the name used in the variable.

char incomingChar;

If you make that change, you'll see that the cast is not necessary, that isdigit() gets a variable of the right size and type, and that the String (ugh?) class gets something to append that it doesn't need to first convert to a String.