Multiple integer values displayed on one 'Stackstring' line [SOLVED!]

I am trying to output two integer values on the same "client.println" output. It is for displaying a hour/min equipment runtime readout.
I can make it print out the 2 values but there is no separation/delineation between value 1 and value 2.

StackString<30> FString = StackString<30>("Integer Values 1 & 2   =   ");
          FString.append(int 1);
          FString.append(int 2);
          client.println(FString.c_str());

That bits works ok but no separation exists between the two fields.
If I add another line to separate the two data values:

     FString.append(int 1);
     FString.append(" / ");
     FString.append(int 2);
     client.println(FString.c_str());

The result is the data ceases updating and the second value is not
even displayed on the screen. But it does compile error free!!! LOL... proving once again bad code compiles as readily as good code....
I am aware of other approaches like char arrays but I am used to this particular approach and it has meant my simple display needs thus far. Until now....

FString.append(int 1);

Does this compile ?

Yes.

Here is actual code:

StackString<75> FString = StackString<75>("                  Great Room Pump Current Hours/Minutes 'ON' time   =   ");
          FString.append(ZP1_hr);
          FString.append(ZP1_run_minutes);
          client.println(FString.c_str());

Please post a full sketch that compiles and illustrates the problem. I have no idea what a SlackString is

likewise - and no idea what a 'Stackstring' is

Lol...Slackstring...Stackstring....what's the difference right....

FYI

Stackstring by Arjen Stens

I have not tried it but there is also

Safestring

and the sketch that illustrates the problem is ...

Sounds to me like the problem is with the display not accepting what you have decided to use as a separator between the two integer values.

Why the need for a single client.println() instead of a sequence of print() and println()? is client implemented in a library that has overloaded print()/println() so that there is a distinction between separate calls to the functions?

< edit > Does the size of the Stackstring need to allow for the additional space needed for the appended text?

output two integer values on the same "client.println"

Use successive client.print() statements, ending with client.println().
Something like:

client.print(value1);
client.print(" / ");
client.println(value2);
2 Likes

No. The Stackstring size declaration is just for the main character string being displayed, not the appended parts AFAIK. I have extra free allocation space with my definition anyway.

That is the way Stackstring is constructed. I have tried your suggestion though but it didn't
work. There is a 'prepend' function you can use instead of, or in combination with 'append', that places a value in front of the main character string. But that makes the webpage wonky looking with that one data field sticking out like a sore thumb.

That might work but it is not utilizing the Stackstring function in the process, which is not ideal.
I may have no choice if no other solution is available. So far all my webpages are utilizing Stackstring so that would be a break from how i normally do it.
In reality I can simply stick the minute value below the hour display on the next line and it works ok but I would rather they are right next to one another.
Ultimately I hope to become more familiar with HTML and make the webpages a little more appealing than the current black text on a white backgroiund with no bells & whistles.

jremington,

I am giving you the Solution flag because you got me thinking in the right direction! :+1: :+1:
I went in and used client.print(PString = StackString<5>(" / ") still inside the Stackstring
domain and then appended the minutes value right behind that. This is something a real code
writer would of realized a lot sooner than myself. Lol.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.