Hello! Please help me! In Report creator I want to calculate area of sheet metall around tube (after insulation) and for that I need to use thinkness of insulation. Thinkness of insulation it's list in plant 3d for example: 30, 40, 60 .... AND IT'S HAVE TYPE FIELD - STRING, but with this type I can't make any expression, for example: [insulationthinkness]*2+[outdiametr]..... becouse, as I undestand, it have to be DOUBLE type..... and the question is: HOW CAN I CONVERT STRING INTO DOUBLE for make any expression?
I will be happy to get any advice!!!!)
Thanks!)
Solved! Go to Solution.
Solved by jabowabo. Go to Solution.
The calculation can be done in Report Creator with a script:
private void cellTotalOd_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { if (cellInsThk.Text == null) return; if (cellOd.Text == null) return; double insThkDbl = System.Convert.ToDouble(cellInsThk.Text); double pipeOdDbl = System.Convert.ToDouble(cellOd.Text); double totalOdDbl = (insThkDbl * 2) + pipeOdDbl; cellTotalOd.Text = System.Convert.ToString(totalOdDbl); }
Result:
Hello Jabowabo!
I have the exact same problem, but Convert.ToDouble doesn't work... 😞
I did everything as shown above and Report Creator wrote me error, that "Input string was not in the correct format".
What am I doing wrong??? Please help me!
Thanks in advance!
The values of my input strings are "25", "32" and "50".
To check the "Convert,ToDouble" I did this simple example:
private void label5_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { double insThkDbl = System.Convert.ToDouble(label3.Text); label5.Text = System.Convert.ToString(insThkDbl); }
Result:
See more pictures in attachments
Not sure what the problem is. You may have a hidden character in your property such as a space or new line. Try this (not tested):
private void label5_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { string numStr = label3.Text; numStr = numStr.Trim(); // <-- this is the typical way to trim spaces, etc. in c#. I assume it will work with report scripts. numDbl = System.Convert.ToDouble(numStr); newNumDbl = numDbl + 2; //<--do your math here string newValStr = System.Convert.ToString(newNumDbl); label5.Text = newValStr; }
Jabowabo, thank you for your answer!
But I made some experiments and figured out, that spaces doesn't causes the error. If the "Insulation thickness" value is "_50" or "50_" and even "5_0", program calculates correctly and the error doesn't occur.(see the picture below).
Script for this picture:
private void label5_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { if (label3.Text == null) return; if (label4.Text == null) return; double insThkDbl = System.Convert.ToDouble(label3.Text); double pipeOdDbl = System.Convert.ToDouble(label4.Text); double totalOdDbl = (insThkDbl * 2) + pipeOdDbl; label5.Text = System.Convert.ToString(totalOdDbl); }
I found, that the error occurs when the "Insulation thickness" value is empty. But I don't understand why this is happening, because I thought, that the "if(label3.Text == null) return;" should solve this problem. Or is this not as?
Try this:
if (System.String.IsNullOrEmpty(label3.Text)) return; if (System.String.IsNullOrEmpty(label4.Text)) return;
Yes! It work!
Thank you very much!
Having a similar problem with the above.
Doing a calcualtion for velocity. When trying to convert the maxflow.Text to a double I get an error that the input string was not in correct format.
The cellSize.Text works fine. Both are strings.
private void maxvelo_BeforePrint_1(object sender, System.Drawing.Printing.PrintEventArgs e) {
double cellSizeDbl = System.Convert.ToDouble(cellSize.Text);
double maxflowDbl = System.Convert.ToDouble(maxflow.Text);
double totalDbl = (maxflowDbl / (((cellSizeDbl/1000)* (cellSizeDbl/1000)) / 4 * 3.142)) ;
maxvelo.Text = System.Convert.ToString(totalDbl);
}
Are you checking your cell values with 'IsNullOrEmpty' before passing them to the ConvertToDouble?
Thanks. Missed that on previous post.
Is there a way to leave the result as blank if one of the field is empty? Also to limit the number of decimal places?
Thanks in advance for your help.
Something like this (not tested):
// check if empty values if (System.String.IsNullOrEmpty(cellSize.Text) || System.String.IsNullOrEmpty(maxflow.Text)) { // leave cell blank maxvelo.Text = ""; } else // values are not empty { double cellSizeDbl = System.Convert.ToDouble(cellSize.Text); double maxflowDbl = System.Convert.ToDouble(maxflow.Text); double totalDbl = (maxflowDbl / (((cellSizeDbl/1000)* (cellSizeDbl/1000)) / 4 * 3.142)) ; // round t two decimal places double totalDblRnd = Math.Round(totalDbl, 2); maxvelo.Text = System.Convert.ToString(totalDblRnd); }
Hi guys!!
How can I take the value of a calculated field and assign to a cell?
It seems hard to me figure it out
You can assign script values via the Properties of the cell.
Hi, I still don't figure it out how those scripts works. I see things "Before Print", "After Print", Data Source Demand....
I wasn't ble to find any documentation.
In this example, I am trying to assign the project number to cell90 via script.. just an example:
private void tableCell90_SummaryCalculated(object sender, DevExpress.XtraReports.UI.TextFormatEventArgs e) {
tableCell90. = General_Project_Number.Value.ToString();
}
not working
There is no debug information. the help is forum and a bit of Google search.