rossi_jeff Posted February 17, 2011 Share Posted February 17, 2011 Is there a way to make this work?I have various values I need to show according to the value of an integer value in a field.I've tried many different syntax but all end in compile errors. Code:switch ( $F{sensor_readings_sensor_type}.intValue() ) { case 0: "Integer"; break; case 1: "String"; break; case 2: "Float"; break; case 3: "Digital"; break; case 4: "Complex"; break; case 5: "Location"; break; case 6: "Diagnostics"; break; case 7: "Bitmap"; break;} Link to comment Share on other sites More sharing options...
cbarlow3 Posted February 17, 2011 Share Posted February 17, 2011 I often just add a field to the query itself so it shows up as a field in iReport:SELECT ...sensor_readings_sensor_type,CASE sensor_readings_sensor_type WHEN 0 THEN 'Integer' WHEN 1 THEN 'String' WHEN 2 THEN 'Float' WHEN 3 THEN 'Digital' WHEN 4 THEN 'Complex' WHEN 5 THEN 'Location' WHEN 6 THEN 'Diagnostics' ELSE 'Unknown'END AS sensor_type_description Link to comment Share on other sites More sharing options...
rossi_jeff Posted February 17, 2011 Author Share Posted February 17, 2011 This worked but I'd still like to know why swictch did not. ("Integer,String,Float,Digital,Complex,Location,Diagnostics,Bitmap".split(",")[$F{sensor_readings_sensor_type}.intValue()]) Link to comment Share on other sites More sharing options...
mdahlman Posted February 17, 2011 Share Posted February 17, 2011 You cannot have full lines of code. (If you see a semi-colon then you're probably going to have trouble.) You can only have expressions.Therefore you could also solve switch type problem like this:sensor_readings_sensor_type == 0 ? 'Integer' : sensor_readings_sensor_type == 1 ? 'String' : sensor_readings_sensor_type == 2 ? 'Float' : and so on...But frankly, your solution appears much nicer. (But I'm not sure whether yours would degrade nicely if the incoming value for sensor_readings_sensor_type is very large or otherwise unexpected.)Regards,Matt Link to comment Share on other sites More sharing options...
noa123 Posted August 3, 2011 Share Posted August 3, 2011 Hi ,What if my field value is a string?I tried this: $F{FIELDV}.equals("ab") ? "aaaa" :$F{FIELDV}.equals("bc") ? "bbbb" : $F{FIELDV}.equals("de") ? "cccc" : ""but it didn't work... any idea?Thank's In Advance. Link to comment Share on other sites More sharing options...
despec Posted August 3, 2011 Share Posted August 3, 2011 Don't forget to enclose in parentheses: ( $F{FIELDV}.equals("ab") ? "aaaa" :( $F{FIELDV}.equals("bc") ? "bbbb" :( $F{FIELDV}.equals("de") ? "cccc" : "" ))) Link to comment Share on other sites More sharing options...
noa123 Posted August 4, 2011 Share Posted August 4, 2011 It work's great!thank's!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now