PDA

View Full Version : Formattig a Value in a Cell of ReportControl



Boris
30-Sep-2010, 12:08 PM
Hi! VDF 16.00

I have tried unsuccessfully to format a number as "###,##0.00" in 3 eRC_Decimal columns of a reportcontrol.

If I use FormatNumber(nvalue,2), it gives me an error before showing the report "invalid simbol in expression"

If I use FormatNumber(nvalue,2), in a eRC_String column, it shows as expected, but then, it is left aligned.

How can I do this?

Thanks in Advanced

Martin
4-Oct-2010, 11:34 AM
1. You need to get latest version.
2. Use the OnSetColumnFormats method

See below, should cover it.... :rolleyes:



Procedure OnSetColumnFormats
//Event Hook
//
//tdRC_Column_Formats tColumn_Formats
//
//Get ptColumn_Formats to tColumn_Formats
//
//Move True to tColumn_Formats[eRC_Dev1].bBold
//Move clBlue to tColumn_Formats[eRC_Dev1].iForeColor
//Move "%.2s" to tColumn_Formats[eRC_Dev1].sFormat
//
//Set ptColumn_Formats to tColumn_Formats
//
End_Procedure




Formatting Numbers:


If the format string is set, the caption text (http://support.dataaccess.com/Forums/XtremeReportControl%7EReportRecordItem%7ECaption.h tml) will be formatted accordingly to this format string before drawing it. Format string is uses a C - like style, see sprintf() C++ function.
Only the "%s" type is supported with the Format method. This means that the Format method will only format strings and treats all numeric values as strings. If a numeric format is desired and can not be displayed properly as a string, then do not enter a Format string, you will need to manually format your data and set this to the Caption (http://support.dataaccess.com/Forums/XtremeReportControl%7EReportRecordItem%7ECaption.h tml) property in the desired string format.

Example Format strings and how they will effect the output (If no Caption (http://support.dataaccess.com/Forums/XtremeReportControl%7EReportRecordItem%7ECaption.h tml) has been set).

Format string Item Value Output "$ %s" 3.15 "$ 3.15" "%s%%" 25 "25%" "$ % 8s" 4.3 "$ 4.3" " $ %.4s" 20.2536 "$ 20.2" "%09s" .1253 "0000.1253" "%06.4s" 3.14325 "003.14" "My name is %s" John "My name is John" "The %s crossed the road" chicken "The chicken crossed the road"


Formatting Dates:

If the item will hold a date value, the Format property can be used to format the date.

The following are valid format flags for date values:



"%a" Abbreviated weekday name
"%A" Full weekday name
"%b" Abbreviated month name
"%B" Full month name
"%c" Date and time representation appropriate for locale
"%d" Day of month as decimal number (01 - 31)
"%H" Hour in 24-hour format (00 - 23)
"%I" Hour in 12-hour format (01 - 12)
"%j" Day of year as decimal number (001 - 366)
"%m" Month as decimal number (01 - 12)
"%M" Minute as decimal number (00 - 59)
"%p" Current locale's A.M./P.M. indicator for 12-hour clock
"%S" Second as decimal number (00 - 59)
"%U" Week of year as decimal number, with Sunday as first day of week (00 - 53)
"%w" Weekday as decimal number (0 - 6; Sunday is 0)
"%W" Week of year as decimal number, with Monday as first day of week (00 - 53)
%x" Date representation for current locale
"%X" Time representation for current locale
"%y" Year without century, as decimal number (00 - 99)
"%Y" Year with century, as decimal number
"%z", "%Z" Time-zone name or abbreviation; no characters if time zone is unknown
"%%" Percent sign
"%#c" Long date and time representation, appropriate for current locale. For example: "Tuesday, March 14, 1995, 12:41:29".
"%#x" Long date representation, appropriate to current locale. For example: "Tuesday, March 14, 1995".
"%#d", "%#H", "%#I", "%#j", "%#m", "%#M", "%#S", "%#U", "%#w", "%#W", "%#y", "%#Y" Remove leading zeros (if any).

Boris
4-Oct-2010, 03:21 PM
I'm getting a compile error "Undefined symbol in argument ERC_DEV1"

I'm unable to use SVN. I downloaded the latest executable on the site.

Boris
4-Oct-2010, 03:39 PM
Ok, I replaced erc_dev1 with erc_string. Now this function is Right aligning all of the string columns, how can I limit that to just one particular column?

Boris
4-Oct-2010, 04:14 PM
Hi! Martin, finally I got it working in a different way. I just set my columns to erc_string and just use the formatnumber function and use the following code:



Procedure OnCreateColumn Integer iColumn Handle hoCol
If (iColumn=6 or iColumn=8 or iColumn=10) Set ComAlignment of hoCol to OLExtpAlignmentRight //Set ComHeaderAlignment of hoCol to OLExtpAlignmentCenter
End_Procedure


I even reordered the columns and it seems to work.

Thanks a lot.

Martin
5-Oct-2010, 02:40 AM
Cool