Solved

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

Posted on 2004-10-28
514 Views
Last Modified: 2011-10-03
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
Question by:Cloud9_User
    15 Comments
     
    LVL 10

    Expert Comment

    by:ebolek
    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 Comment

    by:Cloud9_User
    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
     
    LVL 10

    Expert Comment

    by:ebolek
    did you chnage it  to basic syntax
    0
     
    LVL 10

    Expert Comment

    by:ebolek
    basic sysntax is very much vb
    0
     

    Author Comment

    by:Cloud9_User
    How do you mean did i change it to basic syntax?

    Does Cr9 support two languages or something?
    0
     
    LVL 10

    Assisted Solution

    by:ebolek
    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 Comment

    by:Cloud9_User
    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 Comment

    by:Cloud9_User
    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
     
    LVL 10

    Expert Comment

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

    0
     
    LVL 28

    Accepted Solution

    by:
    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 Comment

    by:Cloud9_User
    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
     
    LVL 28

    Expert Comment

    by:bdreed35
    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 Comment

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

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

    Expert Comment

    by:bdreed35
    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 Comment

    by:Cloud9_User
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
    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…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    860 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

    14 Experts available now in Live!

    Get 1:1 Help Now