Jump to content

proplem with colors

- - - - -

  • Please log in to reply
5 replies to this topic

#1
cesarg

cesarg

    Newbie

  • Members
  • Pip
  • 9 posts
hello
i am trying to elaborate a program that reads the different color rings on resistances.
after i declare all the colors i will be utilizing, i want to write an instruction that will not permit me to utilize the colors that i havent included in my code
if (col != Color.Black || Color.Blue || Color.Yellow || Color.White || Color.Gray || Color.Purple || Color.Orange || Color.Red || Color.Brown)
{
MessageBox.Show("COLOR NO VALIDO");
}
this is what i am trying to do. an error appears something about i cant use that type of operator because it generates bool
can someone give me a hand with this

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Your issue is that Color.Blue is not a Boolean statement, you must use col != in every one of the parameters of the if statement.

Further, if the colour is Blue, then it will not be Yellow, and will fall through to the message box. You must use the && operator (AND, or whichever your language provides for you) so that only if all are not true than it will evaluate.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
cesarg

cesarg

    Newbie

  • Members
  • Pip
  • 9 posts
thank you!!

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200

cesarg said:

thank you!!
According to Zekedragon, in a blog post that had been made for your post, you can use a contains method to easier add more colours:
http://forum.codecal...lem-colors.html

Generally, an array or collection would be used instead of an IF statement, as this allows similar data to be put together (colours), and allow easy lookup.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
cesarg

cesarg

    Newbie

  • Members
  • Pip
  • 9 posts
thanks for the tip. are C# collections similar to javascript collections? do they handle built in methods like contains?

#6
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Javascript? You weren't specific about what language you were using, I had assumed you were using Java. You can't do what I gave you in Javascript, as far as I know there is no ArrayList object. Instead just use an Array object and a for loop.
for (other_color in [[COLOR=#333333]Color.Black, Color.Blue, Color.Yellow, Color.White, Color.Gray, Color.Purple, Color.Orange, Color.Red, Color.Brown])
[/COLOR]{
[COLOR=#333333]    if (col != other_color)[/COLOR][COLOR=#333333]
[/COLOR][COLOR=#333333]    {[/COLOR][COLOR=#333333]
[/COLOR][COLOR=#333333]        MessageBox.Show("COLOR NO VALIDO");
[/COLOR][COLOR=#333333]        break;
[/COLOR][COLOR=#333333]    }
}[/COLOR]

EDIT: Wait, are you doing this in C#? I don't know a word of C#, so I can't really help you there... :(
Wow I changed my sig!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users