Serial.print help please

Hello Forum. My first post so thanks in advance from a 'newbie' on here.

I have borrowed some code from Topic 6724.0, a most interesting and helpful topic too ! Thank you epossum and others.

I need a little help please from you clever guys out there with a small mod to the Serial.print I am using....

The code below allows print at locations on my LCD, works fine but I would like to modify by removing the "\e[0;14H from the first line and adding it to the second Serial.print line so it contains the "\e[0;14H and the InTotal variable, so far I cant get it to work.

Serial.print("\e[0;0H Counts:\e[0;14H");

Serial.print(InTotal);

Once again thank you in advance and keep up the good work.

Regards. UKPete

Not sure why you'd want to do that.
What's wrong with having it as two prints?

Hello UKPete,

Yes. You could do it. It is however probably not a good idea.

Serial.print expects data of various types. Your first Serial.print prints data of type "String" to the Serial Port. You do not say what data type the variable InTotal has and it may not matter.

You could use Serial.print("\e[0;14H" + (String)InTotal); Essentially, you are converting the variable InTotal to a string type and concatenating it to the end of the first string.

It will work. But it also causes the Compiler to add code for converting the variable to a string.

Of course, you could also use something like:

Serial.print("\e[0;14H"); Serial.print(InTotal);

or

Serial.print("\e[0;14H");
Serial.print(InTotal);

if you are just concerned with putting the two together in the code and not relying on the preceding Serial.print Statement.

Thank you for your help JaBa.
Reason for the help being I have the 3 lines of Serial.print positioning InTotal at various locations on the LCD by changing the "\e[x;yH" coords. 12 locations in fact so am trying to get the first part of the code Serial.print("\e[x;yH Counts:"); done in Setup() so only variables need to be be re-printed as and when they change, hope that makes sense. All the best. UKPete

I have the 3 lines of Serial.print positioning InTotal at various locations on the LCD by changing the "\e[x;yH" coords.

That sounds like a function that takes the coordinates as parameters and data to be printed would be a good idea. Write the function once and use it wherever you need it. Within reason it does not matter how many lines of code are in the function. Once it is written just use it like the built in functions.