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
5 replies to this topic
#1
Posted 24 August 2011 - 08:58 PM
|
|
|
#2
Posted 25 August 2011 - 12:50 AM
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.
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.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 25 August 2011 - 02:12 PM
thank you!!
#4
Posted 25 August 2011 - 04:24 PM
cesarg said:
thank you!!
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.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#5
Posted 25 August 2011 - 04:30 PM
thanks for the tip. are C# collections similar to javascript collections? do they handle built in methods like contains?
#6
Posted 25 August 2011 - 04:59 PM
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.
EDIT: Wait, are you doing this in C#? I don't know a word of C#, so I can't really help you there... :(
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


Sign In
Create Account

Back to top









