Statements on the same line

This forum is for all topics related to Simulator for Arduino v0.97. Please include sample code where possible.

Moderator: Adrian

kenster1965
Master Class
Posts: 10
Joined: Sat Aug 04, 2012 2:16 am

Statements on the same line

Postby kenster1965 » Mon Aug 06, 2012 1:57 am

This may be a known issue or just me? Often I place multiple statements on the same line where (to me) it makes sense.

In this case my code looked like this:

Code: Select all

   Serial.print(millis()/1000);   Serial.print(",");   
   Serial.print(temperatureF);      Serial.print(",");
   Serial.print(RH);            Serial.print(",");
   Serial.print(RHaverage);      Serial.print(",");
   Serial.print(RHoldVaule);      Serial.print(",");


And I get the failure “
Error – evaluate called 30 times
Serial.print(temperatureF); Serial.print(",");


I thought it was something with the fact that temperature is a floating number. So I played around with the statements and below is what worked:

Code: Select all

   Serial.print(millis()/1000);
   Serial.print(",");   
   Serial.print(temperatureF);
   Serial.print(",");
   Serial.print(RH);      
   Serial.print(",");
   Serial.print(RHaverage);
   Serial.print(",");


In the below code the top line does not generate an error, but the output is a crazy floating number:

Code: Select all

   Serial.print(millis()/1000);Serial.print(",");   Serial.print(temperatureF);   Serial.print(",");
   Serial.print(RH);
   Serial.print(",");
   Serial.print(RHaverage);
   Serial.print(",");
Thanks,
Ken

Simulator_admin
Site Admin
Posts: 237
Joined: Thu Feb 02, 2012 6:07 pm

Re: Statements on the same line

Postby Simulator_admin » Tue Aug 14, 2012 11:16 pm

OK, this goes back some way. The Simulator can evaluate two code segments on the same line separated by a ; but only if there are no strings using the quote marks as in "this is a string". The code below seems to work since the comma is defined in the string s above. Strings are very hard to work around, and the Simulator should really strip all the strings out of any code and save them otherwise it is hard to step around any keywords inside the strings. We may have to do some rework here. Thanks for pointing this out.

Code: Select all

string s = ",";
float temperatureF = 12.3;
float RH=34.5;
float RHaverage = 56.7;
float RHoldVaule = 67.8;


void setup(){

   Serial.begin(9600);
   Serial.print(millis()/1000);   Serial.print(s);   
   Serial.print(temperatureF);      Serial.print(s);
   Serial.print(RH);            Serial.print(s);
   Serial.print(RHaverage);      Serial.print(s);
   Serial.print(RHoldVaule);      Serial.print(s);

kenster1965
Master Class
Posts: 10
Joined: Sat Aug 04, 2012 2:16 am

Re: Statements on the same line

Postby kenster1965 » Wed Aug 15, 2012 12:39 am

Thanks for the heads-up. Good to know about not using strings on a multiple code line. I know that it's not good practice, But I do catch myself doing that also when debugging.

Just a thought, here, but when the Sim evaluates the code and finds an error it comes up with the error window, you could add a bit of text in the window after the error code with a few notes to possible causes. IE. Quoted string(s) not allowed with multiple code segments.

Also by doing this you could put know issues and work arounds there as a place holder for the lower priority issues so you can get the next version out the door.

Just a thought ;)
Thanks,
Ken

engladBib
Posts: 2
Joined: Fri Sep 08, 2017 7:54 pm

Learn English

Postby engladBib » Thu Sep 14, 2017 12:15 am

Интересно,


Return to “Version 0.97”

Who is online

Users browsing this forum: No registered users and 1 guest