Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set Field Properties (change decimals using API)

Posted on 2005-05-16
6
Medium Priority
?
496 Views
Last Modified: 2008-01-09
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!
0
Comment
Question by:ositear
  • 4
  • 2
6 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 14010599
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
0
 
LVL 1

Author Comment

by:ositear
ID: 14011054
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".


0
 
LVL 101

Expert Comment

by:mlmcc
ID: 14013795
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
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 101

Accepted Solution

by:
mlmcc earned 1500 total points
ID: 14016139
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
  1
else if {?NumZeros} = 1 then
  1.0
else if {?NumZeros} = 2 then
  1.00

etc for the number of zeros you want.

mlmcc

0
 
LVL 1

Author Comment

by:ositear
ID: 14019155
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
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 14020659
The CRAXDRT is the RDC which replaced the OCX method in CR9.  The RDC was itroduced with CR8.

mlmcc
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

810 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