• Status: Solved
• Priority: Medium
• Security: Public
• Views: 531

# Quick 500 - The syntax for a Do while loop in a CR9 function?

Ok... Just a quick one,

i have a series of decimal hours which need to rounded down to the nearest quarter, this is my code that i have in a function:

NumberVar Decimal:= 0;
NumberVar Decimal_After_Point := 0;

//Debug
Decimal := %%%%%VALUE%%%%%

Decimal_After_Point := decimal - int(Decimal);
Decimal := int(decimal);
while Decimal_After_Point <> 0 AND Decimal_After_Point <> 0.25 AND Decimal_After_Point <> 0.5 AND Decimal_After_Point <> 0.75 do
(
Decimal_After_Point := Decimal_After_Point - 0.01
);

Decimal  + Decimal_After_Point

Now, i've never done a loop in Crystal reports before, so i was wondering if you guys could tell me where i'm going wrong?

For example, the following are examples and what they should equal:
13.56 = 13.45
2 = 2.00
3.14 = 3.00
56.45 = 56.45
56.44 = 56.30

You get the picture, the initial value will be passed in as 'decimal' and the new value must be returned
0
Cloud9_User
• 7
• 5
• 3
2 Solutions

Commented:
Do While iDecimal_After_Point <> 0 AND Decimal_After_Point <> 0.25 AND Decimal_After_Point <> 0.5 AND Decimal_After_Point <> 0.75
Decimal_After_Point := Decimal_After_Point - 0.01

Loop
This is how you do it for Basic syntax

Regards
Emre
0

Author Commented:
Er... that looks a little bit too much like VB and a little bit far away from Crystal Reports...

And it brings back the Error:  The Keyword 'Do' is missing.

Unfortunatly, i need the syntax in CR9 format, hence i'm having the problems in the first place :/

thanks any way tho.
0

Commented:
did you chnage it  to basic syntax
0

Commented:
basic sysntax is very much vb
0

Author Commented:
How do you mean did i change it to basic syntax?

Does Cr9 support two languages or something?
0

Commented:
On the formula editor, you can chnage the syntax that formula understands.There are two syntaxes

crytsal syntax: looks like c
basic syntax: looks like vb

It is a dropdown box
0

Author Commented:
Well Bloody hell, i've been working on Crystal Reports for over a week now and i've only just noticed that box. Bugger.

I have still done the rest of the function in Crystal Syntax anyways, so i still need to know how it's done as above.

Can you toggle the Basic and Crystal syntax by each function or to use Basic syntax do i have to re-write all my other functions?
0

Author Commented:
I'll give you 100 points for that by the way, you indirectly answered my question :P

The original question now stands for 400.
0

Commented:
No each formula can have different sysntax but all the syntax in one formula should written the same.

0

Commented:
This should work for you in Crystal syntax in place of your loop:

numbervar decimal := 56.44; //add you field here instead of the number
numbervar decimal_val := 0;

select (decimal-int(decimal))
case is < .15 : decimal_val := .0
case is < .30 : decimal_val := .15
case is < .45 : decimal_val := .30
default          : decimal_val := .45;

int(decimal) + decimal_val;
0

Author Commented:
bdreed, i think thats the second 500points youve had off me in as many days :))

Thanks bud, works like a charm.

I am going to award 100 to ebo for pointing out how stupid i am, but you get the 400!

Thanks everyone
0

Commented:
I am going to keep playing with it because I know I can simplify it a bit more.  If I come up with something I will post it here.
0

Author Commented:
Nah... its ok, that works like a charm...
If it ain't broke.....

Just get prepared for my next question tomorrow.... :)
0

Commented:
Here it is more streamlined.  Either one will work for you:

numbervar actual := 13.56;//change to database field
int(actual) + (int(((actual - int(actual))*100) / 15) * .15)

I am ready and waiting for the next one ;)
0

Author Commented:
Lol, cheers bud... i think i'll use the previous tho, if i ever come back to redo the formula i won't know what it even does!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.