Determine if string equals a GUI colour
- PuzzledGreatly
- Posts: 1303
- Joined: 29 Sep 2013, 22:18
Determine if string equals a GUI colour
Does a 6 letter long string always translate to an AHK GUI color? How to determine if a string is a legitimate color or not? Thanks.
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: Determine if string equals a GUI colour
Any 6 digit hexadecimal value is a valid color. You can use code similar to the follow to check if a string is a 6 digit hex value...
Note: It is sometimes possible to use common color names (such as "Red", "Blue", "Yellow", etcetera) instead of hex values, and the above code does not check for those.
Code: Select all
String := "A1B2C3"
If (String is xdigit) AND (StrLen(String) = 6)
MsgBox %String% is a valid color.
Else
MsgBox %String% is NOT a valid color.
Re: Determine if string equals a GUI colour
Shadowpheonix
If (String is xdigit) Uses expression syntax. It's the same as doing If ("xxxxxx" "" "")
Code: Select all
String := "xxxxxx"
If (String is xdigit) AND (StrLen(String) = 6)
MsgBox %String% is a valid color.
Else
MsgBox %String% is NOT a valid color.
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: Determine if string equals a GUI colour
Kon,
Thank you for pointing that out. I must have mis-typed something when I tested the original code with various values, as it appeared to work correctly. However, I just retested it now and it is definitely failing.
Here is the corrected code...
Thank you for pointing that out. I must have mis-typed something when I tested the original code with various values, as it appeared to work correctly. However, I just retested it now and it is definitely failing.
Here is the corrected code...
Code: Select all
String := "xxxxxx"
If String is xdigit
{
If (StrLen(String) = 6)
MsgBox %String% is a valid color.
}
Else
MsgBox %String% is NOT a valid color.
Re: Determine if string equals a GUI colour
Code: Select all
Gui, Color, 7f
Gui, Show, w400 h400
And as you mentioned, the color names are also valid: Black,Green,Silver,Lime,Gray,Olive,White,Yellow,Maroon,Navy,Red,Blue,Purple,Teal,Fuchsia,Aqua
So maybe if var in matchlist could be used too.
Who is online
Users browsing this forum: Rohwedder and 189 guests