Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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>"
Reply With Quote
  #3 (permalink)  
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.
Reply With Quote
  #4 (permalink)  
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.
======================================
Reply With Quote
  #5 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:53 AM.


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