Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2004, 12:01 PM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default Randomizing

Hello all!

Anyone have a tips on randomizing? I need to randomly generate a background color for a table and I'm unsure of how randomize.

Thanks!
Chris
 
Old April 20th, 2004, 01:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey your lucky day I was just learning the Randomize this morning

Dim BgColor(5)
Dim intColor

'List your colors
BgColor(0) = "Color1"
BgColor(1) = "Color2"
BgColor(2) = "Color3"
BgColor(3) = "Color4"
BgColor(4) = "Color5"
BgColor(5) = "Color6"

'Randomly select a number in the array
RANDOMIZE
intColor = Int((6 - 1 + 1) * Rnd)

Response.Write BgColor(intColor) & " BgColor<BR>"
 
Old April 20th, 2004, 02:15 PM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

Your code worked like a charm! Now allow me to add to the previous question.

Is it possible to place that in loop? I've tried and it runs once, then errors with " type mismatch - line 122 (line 122 is where Dim BgColor(5) resides in the code)

I'm obviously doing something wrong, but I can't figure it out.
 
Old April 20th, 2004, 08:12 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Put the Dim statement outside of the loop.(That is before the loop)



======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old April 21st, 2004, 11:31 AM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

I originally tried that with the same result. Came back and started fresh this morning and it worked correctly.

Thanks to both of you for the help!

Chris




Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ randomizing The Bard C++ Programming 1 November 17th, 2006 08:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.