Link to home
Start Free TrialLog in
Avatar of ositear
ositear

asked on

Set Field Properties (change decimals using API)

Hi!

How do I set a field property using an API function? (Visual Basic)

I have a db field (let´s say... {article.price}) with 2 decimal places (ie: xxxxxx.xx), but I need to set in runtime the number of decimal places. (I am using Visual Basic)
If I could set field properties with an API call I would manage to do, but I couldn´t find an api call for that, neither for changing decimal places directly in visual basic code.


Tnx in advence!
Avatar of Mike McCracken
Mike McCracken

You can use a formula in Crystal to set the number of decimal places.

Try
ToText({article.price}, n)  where n is the number of decimal places desired.

mlmcc
Avatar of ositear

ASKER

Yes, that would do, but I´d prefer something that does not involve editing the crystal document, so I can transparently handle the issue on the application layer. (I would have to edit about 300 reports :) )

Anyway, I need a way to set a field property, not replacing a field with a formula, since I would have to replace every field for a formula.

I can accept a SINGLE formula which can be called from VB before printing out the report that sets de number of decimals.
Something like:

SetDecimals({article.price}, n);
SetDecimals({article.price2}, n);
SetDecimals({article.price3}, n);
SetDecimals({article.price4}, n);

and somehow set the "n" value from visual basic, but yet, I can´t find any function like "SetDecimals".


Don't have CR here to try.  I believe you can programmitacally access the formula fields for a field to set the format.

I'll check tonight.

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ositear

ASKER

Geee, how couldn´t I see that, hehe
Great, that would do.
Just a thing:
the parameter is not 1, 1.0, 1.00, you have to enter directly the number of decimals: 1,2,3,4...

Also I found this here:
http://www.codecomments.com/archive342-2005-4-426887.html

This would look for all of the FieldObjects in the report's Details
section, and if the field is a Number type field, it will change the
rounding and decimal places:

Dim crxDbFld As CRAXDRT.DatabaseFieldDefinition
Dim crxFldDef As CRAXDRT.FieldDefinitions
Dim crxSection As CRAXDRT.Section
Dim crxFldObj As CRAXDRT.FieldObject
Dim crxRptObjs As CRAXDRT.ReportObjects

On Error Resume Next

Set crxSection = Report.Sections("D")
Set crxRptObjs = crxSection.ReportObjects
For Each crxFldObj In crxRptObjs
If crxFldObj.Kind = crDatabaseField Then
Set crxDbFld = crxFldObj.Field
If crxDbFld.ValueType = crNumberField Then
crxFldObj.DecimalPlaces = 2
crxFldObj.RoundingType = crRoundToHundredth
End If
End If
Next


but since I´m using the OCX I don´t have the "CRAXDTR".
Thanks for your time, accepted answer
The CRAXDRT is the RDC which replaced the OCX method in CR9.  The RDC was itroduced with CR8.

mlmcc