Solved

Create Random color (Visual Basic)

Posted on 2004-04-22
7
2,971 Views
Last Modified: 2013-12-04
how to create random color using RGB function without repeat of the same color or color code.

0
Comment
Question by:cyseng10
  • 3
7 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
Comment Utility
Hi cyseng10,

Firstly I wouldn't use the RGB(R,G,B) function. Use a long instead. Which is actually what is returned by this function.

Something simple like:

Randomize
Color = Rnd() * &HFFFFFF

Will get you a random color, set the seed based on date & time for more randomness.

Then you need to store the returned long in a searchable list so that you can check whether it has been used before. This could be anything that makes sense, a disconnected recordset or an array or collection or whatever you like really as long as it can be searched for a matching value fairly quickly and easily.

Tim Cottee
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 1

Author Comment

by:cyseng10
Comment Utility
thank you for suggestion. i will try on it ..

how i check if the color is black or dark? i will not useblack or too dark color. the color will apply into flexgrid.


0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
cyseng10,

That gets quite complicated. There is a question somewhere on here that addresses this, will see if I can find it.

Tim.
0
 
LVL 2

Expert Comment

by:Ivan_Skrinjaric
Comment Utility
Yuo can control color brigtnes with brightnes variable.

    Dim color   As String
    Dim brightnes As Integer
    Dim invbrightnes As Integer

    brightnes = 200
    invbrightnes = 255 - brightnes

    color = RGB(brightnes + (Rnd * invbrightnes ), brightnes + (Rnd * invbrightnes ), brightnes + (Rnd * invbrightnes ))

Ivan.
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
cyseng10,

Why the C grade? I haven't yet been able to locate the question I referred to. And now it is extremely unlikely that I will waste my time doing so. The answer given to the original (not subsequent) question was perfectly reasonable. If not then you should have explained why and allowed me to improve the answer. Please consider requesting a grade change by posting a question in CS to that effect.

Tim.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Game Asset Design and Performance. 7 83
powerN  challenge 3 47
mapAB Challlenge 35 84
C# code editing and collaboration 3 40
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
A short article about a problem I had getting the GPS LocationListener working.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now