Monday, January 21, 2008

How to use ReplicateString, Replace, Len in Crystal Report

today i would share about coding in crystal report. how to use replicatestring, replace, and len function.
in my example, i would try to display a number "0000001" from recordnumber.

here the step on creating the code:
1. first we must convert the recordnumber from integer into text.
ToText(RecordNumber) --> "1.00"
2. we must hidden or replace ".00" with blank character. we can use replace function
(Replace (ToText(RecordNumber),".00","") --> "1"

3. then we must count the length of result
len(Replace (ToText(RecordNumber),".00","")) --> length = 1
4. we must count how much we would to replicate the character "0"
in this example, i would like display 7 digits.
7-len(Replace (ToText(RecordNumber) --> number to repilcate = 6
5. and then we replicate the character "0"
ReplicateString ("0",7-len(Replace (ToText(RecordNumber),".00",""))) --> "000000"
6. the last step, we concatenate the string with the actual number
ReplicateString ("0",7-len(Replace (ToText(RecordNumber),".00",""))) + Replace (ToText(RecordNumber),".00","") --> "0000001"

if the recordnumber was 987, then the result was: "0000987"

oks, have a nice try.. cu...

No comments:


Microsoft News for ADO .NET:

Our Email Address: