Set Field Properties (change decimals using API)

Posted on 2005-05-16
Last Modified: 2008-01-09

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!
Question by:ositear
    LVL 100

    Expert Comment

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

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

    LVL 1

    Author Comment

    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".

    LVL 100

    Expert Comment

    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.

    LVL 100

    Accepted Solution

    Try this

    Create a parameter so the application can pass the number of 0's to the report

    Select the field
    Right Click and select FORMAT
    Click the Formula button next to DECIMALS
    Formula to enter

    if {?NumZeros} = 0 then
    else if {?NumZeros} = 1 then
    else if {?NumZeros} = 2 then

    etc for the number of zeros you want.


    LVL 1

    Author Comment

    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:

    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

    but since I´m using the OCX I don´t have the "CRAXDTR".
    Thanks for your time, accepted answer
    LVL 100

    Expert Comment

    The CRAXDRT is the RDC which replaced the OCX method in CR9.  The RDC was itroduced with CR8.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
    There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now