Programming algorithm help...

Electric Amish

Elite Member
Oct 11, 1999
23,578
1
0
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
 

Electric Amish

Elite Member
Oct 11, 1999
23,578
1
0
Originally posted by: cr4zymofo
Arrays?


Can't really by that much programming. Just some boolean expression that's true for 4 records, false for 4 records, true for 4 records, etc...

have you tried replacing the 2 with a 4 ?

That just highlight's every 4th record.
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
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.
 

spartan

Senior member
Oct 9, 1999
330
0
0
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).
 

agnitrate

Diamond Member
Jul 2, 2001
3,761
1
0
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
 

sillymofo

Banned
Aug 11, 2003
5,817
2
0
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.
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
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
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
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.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
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
 

Fatalist

Member
Nov 25, 2001
26
0
0
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
 

GL

Diamond Member
Oct 9, 1999
4,547
0
0
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!
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
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.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
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.
 

FeathersMcGraw

Diamond Member
Oct 17, 2001
4,041
1
0
Take the recordnumber mod 8. If the result is less than 4, highlight.

Or: what notfred said (isn't that a 90's one-hit wonder?)
 

GL

Diamond Member
Oct 9, 1999
4,547
0
0
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
 

Electric Amish

Elite Member
Oct 11, 1999
23,578
1
0
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...

 

notfred

Lifer
Feb 12, 2001
38,241
4
0
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.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
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.
 

FeathersMcGraw

Diamond Member
Oct 17, 2001
4,041
1
0
Originally posted by: Electric Amish
CLOSE!! This code gives me 1,2,3 (Highlighted); 4,5,6,7(not Highlighted); 8,9,10 (highlighted), etc...

Okay, (recordnumber - 1) mod 8 < 4.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |