• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Programming algorithm help...

Electric Amish

Elite Member
I can't quite get a handle on how to do this.

In Crystal Reports you can put in a little script that will highlight every-other line (if remainder (recordnumber, 2) <> 0 then Silver else NoColor).

It basically uses a "MOD" function and acts on even/odd numbers.

I need something that will do that for 4 records every 4 records (NOT EVERY 4th RECORD). e.g. 1,2,3,4 (highlighted); 5,6,7,8 (Not Highlighted); 9,10,11,12 (Highlighted) etc...

Any suggestions would be appreciated.

amish
 
Cast each item into a text entry field and then concatenate them along with the numerical id for that line. You should then be able to derive the appropriate color scheme according tot he mod argument that is spat out.
 
Never used Crystal Reports before but it should be something like this.

(if (remainder (recordnumber, 8) >= 0)) or (remainder (recordnumber, 8) < 4) then Silver else NoColor).
 
I would probably use a bool that you set true/false every time you hit an element where (element % 4) == 0 and you highlight depending on the bool

starting @ 0, bool is true, loop(0->4 and highlight)
4%4 == 0, bool is false, (loop 5->8 and don't highlight since bool false), but at the end of the 8, you see 8%4 == 0, bool is true again.

-silver
 
Originally posted by: Skoorb
Cast each item into a text entry field and then concatenate them along with the numerical id for that line. You should then be able to derive the appropriate color scheme according tot he mod argument that is spat out.
tedious, but will work, I guess you don't have that many lines to type.
 
Originally posted by: cr4zymofo
Originally posted by: Skoorb
Cast each item into a text entry field and then concatenate them along with the numerical id for that line. You should then be able to derive the appropriate color scheme according tot he mod argument that is spat out.
tedious, but will work, I guess you don't have that many lines to type.
LOL 🙂
 
4x1 = 4
4x2 = 8
4x3 = 12

If you want 1-4 highlighted and then 9 - 12, take 4 times a number to get a total. If you have to multiply by odd, highlight, if you have to multiply by even, don't highlight.
 
All you need is the modulus to do this. Crystal Reports has the same modulus operator as VB, or so I thought. I know you're a VBer Amish, so here's some code to demonstrate:

Dim i
i = 0

Dim sColor
sColor = "Blue"

Do While i < 20
If i Mod 4 = 0 Then
sColor = IIf(sColor = "Blue", "Red", "Blue")
End If
i = i + 1
Loop
 
In Crystal Reports you can put in a little script that will highlight every-other line (if remainder (recordnumber, 2) <> 0 then Silver else NoColor).

You need to use floor(recordnumber / 4) in place of recordnumber.
In Excel, FLOOR is also called INT
I am not sure what it would be called in Crystal Reports

if remainder( floor( recordnumber / 4 ), 2 ) <> 0 then Silver else NoColor
 
Originally posted by: Electric Amish
I can't quite get a handle on how to do this.

In Crystal Reports you can put in a little script that will highlight every-other line (if remainder (recordnumber, 2) <> 0 then Silver else NoColor).

It basically uses a "MOD" function and acts on even/odd numbers.

I need something that will do that for 4 records every 4 records (NOT EVERY 4th RECORD). e.g. 1,2,3,4 (highlighted); 5,6,7,8 (Not Highlighted); 9,10,11,12 (Highlighted) etc...

Any suggestions would be appreciated.

amish

Never used Crystal Reports but I'd imagine this would work (using pseudocode):

Note the following properties:

floor(1/4) = 0 and 1 mod 4 = 1
floor(2/4) = 0 and 2 mod 4 = 2
floor(3/4) = 0 and 3 mod 4 = 3
floor(4/4) = 1 and 4 mod 4 = 0

floor(5/4) = 1 and 5 mod 4 = 1
floor(6/4) = 1 and 6 mod 4 = 2
floor(7/4) = 1 and 6 mod 4 = 3
floor(8/4) = 2 and 8 mod 4 = 0

floor(9/4) = 2 and 9 mod 4 = 1
floor(10/4) = 2 and 10 mod 4 = 2
floor(11/4) = 2 and 11 mod 4 = 3
floor(12/4) = 3 and 12 mod 4 = 0

floor(13/4) = 3 and 13 mod 4 = 1
floor(14/4) = 3 and 14 mod 4 = 2
floor(15/4) = 3 and 15 mod 4 = 3
floor(16/4) = 4 and 16 mod 4 = 0

.
.
.

So I'd imagine what you want is to do the following:

Colour all records that fulfill any (i.e. logical OR) of these properties:
1) The floor of the recordnumber divided by 4 is even.
2) The floor of the recordnumber divided by 4 is odd AND the recordnumber modulo 4 is 0.

EDIT
If record numbers start at 0 then you don't need part 2) of course. Not sure about Crystal Reports but since you started the record numbering at 1 I figured that's what it starts at!
 
I'm not familiar with Crystal reports syntax, but here it is in some generic pseudocode:

if(recordnumber % 8 < 4){
Silver
}
else{
NoColor
}

% is the modulus operator, as it is in C and Java.


Edit: Some of you guys either don't seem to understand the problem, or are just way off in your answers.
 
Originally posted by: GL
Originally posted by: Electric Amish
I can't quite get a handle on how to do this.

In Crystal Reports you can put in a little script that will highlight every-other line (if remainder (recordnumber, 2) <> 0 then Silver else NoColor).

It basically uses a "MOD" function and acts on even/odd numbers.

I need something that will do that for 4 records every 4 records (NOT EVERY 4th RECORD). e.g. 1,2,3,4 (highlighted); 5,6,7,8 (Not Highlighted); 9,10,11,12 (Highlighted) etc...

Any suggestions would be appreciated.

amish

Never used Crystal Reports but I'd imagine this would work (using pseudocode):

Note the following properties:

floor(1/4) = 0 and 1 mod 4 = 1
floor(2/4) = 0 and 2 mod 4 = 2
floor(3/4) = 0 and 3 mod 4 = 3
floor(4/4) = 1 and 4 mod 4 = 0

floor(5/4) = 1 and 5 mod 4 = 1
floor(6/4) = 1 and 6 mod 4 = 2
floor(7/4) = 1 and 6 mod 4 = 3
floor(8/4) = 2 and 8 mod 4 = 0

floor(9/4) = 2 and 9 mod 4 = 1
floor(10/4) = 2 and 10 mod 4 = 2
floor(11/4) = 2 and 11 mod 4 = 3
floor(12/4) = 3 and 12 mod 4 = 0

floor(13/4) = 3 and 13 mod 4 = 1
floor(14/4) = 3 and 14 mod 4 = 2
floor(15/4) = 3 and 15 mod 4 = 3
floor(16/4) = 4 and 16 mod 4 = 0

.
.
.

So I'd imagine what you want is to do the following:

Colour all records that fulfill any (i.e. logical OR) of these properties:
1) The floor of the recordnumber divided by 4 is even.
2) The floor of the recordnumber divided by 4 is odd AND the recordnumber modulo 4 is 0.

EDIT
If record numbers start at 0 then you don't need part 2) of course. Not sure about Crystal Reports but since you started the record numbering at 1 I figured that's what it starts at!

The division of the recordnumber by 4 is entirely superfluous if you're getting the modulus.
 
Originally posted by: Descartes
Originally posted by: GL
Originally posted by: Electric Amish
I can't quite get a handle on how to do this.

In Crystal Reports you can put in a little script that will highlight every-other line (if remainder (recordnumber, 2) <> 0 then Silver else NoColor).

It basically uses a "MOD" function and acts on even/odd numbers.

I need something that will do that for 4 records every 4 records (NOT EVERY 4th RECORD). e.g. 1,2,3,4 (highlighted); 5,6,7,8 (Not Highlighted); 9,10,11,12 (Highlighted) etc...

Any suggestions would be appreciated.

amish

Never used Crystal Reports but I'd imagine this would work (using pseudocode):

Note the following properties:

floor(1/4) = 0 and 1 mod 4 = 1
floor(2/4) = 0 and 2 mod 4 = 2
floor(3/4) = 0 and 3 mod 4 = 3
floor(4/4) = 1 and 4 mod 4 = 0

floor(5/4) = 1 and 5 mod 4 = 1
floor(6/4) = 1 and 6 mod 4 = 2
floor(7/4) = 1 and 6 mod 4 = 3
floor(8/4) = 2 and 8 mod 4 = 0

floor(9/4) = 2 and 9 mod 4 = 1
floor(10/4) = 2 and 10 mod 4 = 2
floor(11/4) = 2 and 11 mod 4 = 3
floor(12/4) = 3 and 12 mod 4 = 0

floor(13/4) = 3 and 13 mod 4 = 1
floor(14/4) = 3 and 14 mod 4 = 2
floor(15/4) = 3 and 15 mod 4 = 3
floor(16/4) = 4 and 16 mod 4 = 0

.
.
.

So I'd imagine what you want is to do the following:

Colour all records that fulfill any (i.e. logical OR) of these properties:
1) The floor of the recordnumber divided by 4 is even.
2) The floor of the recordnumber divided by 4 is odd AND the recordnumber modulo 4 is 0.

EDIT
If record numbers start at 0 then you don't need part 2) of course. Not sure about Crystal Reports but since you started the record numbering at 1 I figured that's what it starts at!

The division of the recordnumber by 4 is entirely superfluous if you're getting the modulus.

Yup just realized notfred's (and subsequent posters') answer🙂
 
Originally posted by: notfred
I'm not familiar with Crystal reports syntax, but here it is in some generic pseudocode:

if(recordnumber % 8 < 4){
Silver
}
else{
NoColor
}

% is the modulus operator, as it is in C and Java.


Edit: Some of you guys either don't seem to understand the problem, or are just way off in your answers.

CLOSE!! This code gives me 1,2,3 (Highlighted); 4,5,6,7(not Highlighted); 8,9,10 (highlighted), etc...

Descartes- I can't use that because I don't know how many records are going to be pulled from the DB... 🙁

 
Originally posted by: Electric Amish
Originally posted by: notfred
I'm not familiar with Crystal reports syntax, but here it is in some generic pseudocode:

if(recordnumber % 8 < 4){
Silver
}
else{
NoColor
}

% is the modulus operator, as it is in C and Java.


Edit: Some of you guys either don't seem to understand the problem, or are just way off in your answers.

CLOSE!! This code gives me 1,2,3 (Highlighted); 4,5,6,7(not Highlighted); 8,9,10 (highlighted), etc...

Descartes- I can't use that because I don't know how many records are going to be pulled from the DB... 🙁

Hmm, it should give you 0,1,2,3 highlighted and 4,5,6,7 not highlighted.
 
Originally posted by: Electric Amish
Originally posted by: notfred
I'm not familiar with Crystal reports syntax, but here it is in some generic pseudocode:

if(recordnumber % 8 < 4){
Silver
}
else{
NoColor
}

% is the modulus operator, as it is in C and Java.


Edit: Some of you guys either don't seem to understand the problem, or are just way off in your answers.

CLOSE!! This code gives me 1,2,3 (Highlighted); 4,5,6,7(not Highlighted); 8,9,10 (highlighted), etc...

Descartes- I can't use that because I don't know how many records are going to be pulled from the DB... 🙁

That was just an example. It doesn't matter how many records are pulled. Here's the output:

Dim i
i = 0

Dim sColor
sColor = "Blue"

Do While i < 20
If i Mod 4 = 0 Then
If sColor = "Blue" Then
sColor = "Red"
Else
sColor = "Blue"
End If
'sColor = IIf(sColor = "Blue", "Red", "Blue")
End If
WScript.Echo sColor & ":" & CStr(i)
i = i + 1
Loop

Output:

Red:0
Red:1
Red:2
Red:3
Blue:4
Blue:5
Blue:6
Blue:7
Red:8
Red:9
Red:10
Red:11
Blue:12
Blue:13
Blue:14
Blue:15
Red:16
Red:17
Red:18
Red:19

I just put the limit on 20 so it wouldn't go on ad infinitum. Just take the recordnumber mod 4. Note that I couldn't use IIf() because the above is in VBScript.
 
Back
Top