Solved

Create Random color (Visual Basic)

Posted on 2004-04-22
7
2,975 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
ID: 10886974
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
ID: 10887258
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
ID: 10887280
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
ID: 10887323
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
ID: 10946859
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

786 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