Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-28
15
Medium Priority
?
526 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
Comment
Question by:Cloud9_User
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
15 Comments
 
LVL 10

Expert Comment

by:ebolek
ID: 12433773
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
ID: 12433813
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
ID: 12433826
did you chnage it  to basic syntax
0
Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

 
LVL 10

Expert Comment

by:ebolek
ID: 12433829
basic sysntax is very much vb
0
 

Author Comment

by:Cloud9_User
ID: 12433840
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
ebolek earned 400 total points
ID: 12433890
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
ID: 12433912
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
ID: 12433919
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
ID: 12433922
No each formula can have different sysntax but all the syntax in one formula should written the same.

0
 
LVL 28

Accepted Solution

by:
bdreed35 earned 1600 total points
ID: 12434048
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
ID: 12434103
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
ID: 12434151
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
ID: 12434170
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
ID: 12434265
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
ID: 12434475
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

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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. …
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 …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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