quick MOD question

1. Senior Member
Join Date
Dec 1969
Posts
1,407

## quick MOD question

i need to turn any number i get into a number that lies between 0 and 7.<BR><BR>can i use MOD to do this?

2. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: quick MOD question

3. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: quick MOD question

Any number between 0 and 7?<BR><BR>Or we talking about remainders here?<BR><BR>Try describing what you&#039;re after.<BR><BR>Craig.

4. Senior Member
Join Date
Dec 1969
Posts
1,407

## RE: quick MOD question

well, i&#039;m just messing around with the colors of the bars in my bar graph.<BR><BR>the user will be able to move quickly through graph after graph, and i would just like to be able to randomly assign different colored bars with each move through the array of graphs...........this will give them a visual reference, i guess, as they move through the graphs.<BR><BR>so, anyway, i only have 8 colors. the colors exist in an array......so i need to work something out so that element in the array switches each time a new graph is displayed.<BR><BR>i&#039;m thinking i need to use rand() or something like that coupled with the mod function.

5. Senior Member
Join Date
Dec 1969
Posts
1,407

## here's what i've got so far.....

randomize()<BR>num=rnd()<BR>num=num MOD 5<BR><BR>then later on at the bottom of the page<BR><BR>Response.Write CELL_PRE & colors(num) & CELL_MID1 & width & CELL_MID2<BR><BR>and i&#039;m getting weird errors, like subscript out of range [2050]<BR><BR>how could num be 2050?<BR><BR>here&#039;s a larger chunk of the subroutine....<BR><BR> Response.Write OUTER_HEAD<BR> &#039; One row at a time...<BR> For row = 0 To rowCnt<BR> Response.Write "&#060;TR&#062;" & vbNewLine<BR> If titleFld &#062;= 0 Then<BR> Response.Write TITLE_PRE & Data(titleFld,row) & TITLE_POST<BR> End If<BR> Response.Write GROUP_PRE<BR> For df = 0 To dataFldCnt<BR> dmax = CDbl( colMaxes( df ) )<BR> col = dataFlds(df)<BR> colVal = 0 <BR> On Error Resume Next <BR> colVal = CDbl( Data(col,row) ) <BR> On Error GoTo 0<BR> width = Int( ( colVal / dmax ) * maxWidth )<BR> Response.Write CELL_PRE & colors(num) & CELL_MID1 & width & CELL_MID2<BR> If showValue = True Then Response.Write VALUE_PRE & colval & VALUE_POST<BR> Response.Write CELL_POST <BR> Next<BR> Response.Write GROUP_POST<BR> Response.Write "&#060;/TR&#062;"<BR> Next<BR> Response.Write OUTER_TAIL<BR>End Sub

6. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: here's what i've got so far.....

I suggest you read up on what Rnd() will return.<BR><BR>Craig.

7. Senior Member
Join Date
Dec 1969
Posts
96,118

But...<BR><BR>But picking color randomly is a bad idea.<BR><BR>There&#039;s no guarantee that you won&#039;t get 3 blue bars in a row. Or, if you check to make sure that adjacent bars aren&#039;t the same color, there&#039;s no guarantee that you won&#039;t get blue-red-blue-red-blue-red-blue-red.<BR><BR>It&#039;s much cleaner to just use a loop counter and use MOD on that:<BR><BR>&#060;%<BR>colorsArray = Array("red","green","pink","wheat","blue","brown") <BR><BR>For row = 0 TO 113<BR> colorNumber = row MOD ( UBound(colorsArray)+1 )<BR> ...<BR>Next<BR>%&#062;<BR>

8. Senior Member
Join Date
Dec 1969
Posts
1,407

## ahhh....ok, thanks <nm>

nm

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## Wouldn't work, anyway...

...since you choose num at the top, before the loop, *ALL* of your rows will be the SAME color. Surely that&#039;s not what you want.<BR><BR>Knowing the code you are using, and realizing that you only have ONE data field per row (that is dataFldCnt is zero), you could just use<BR> Response.Write CELL_PRE & colors( row MOD (1+UBound(colors)) ) & CELL_MID1 & width & CELL_MID2<BR>

10. Senior Member
Join Date
Dec 1969
Posts
1,407

## i think you misunderstand me....

i do not want alternating bar colors within a graph itself....<BR><BR>i want alternating colors with each move to a new graph. i&#039;m displaying graphs on a page called "scoreboard.asp"<BR><BR>each time i call scoreboard.asp, i would like to randomly choose the color of the bars used in that graph.<BR><BR>i think this will have a visual effect that kind of verifies a move from graph to another (kind of trivial, i know).

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•