Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create Random color (Visual Basic)

Posted on 2004-04-22
7
Medium Priority
?
2,986 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 150 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression

722 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