WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: spl on October 11, 2025, 09:08:41 AM

Title: OT: CLR and System Colors
Post by: spl on October 11, 2025, 09:08:41 AM
The code below will fail with attached error message. The Tech DB has a lot about colors, many which I posted back in the day. But the known system colors are an enum and would like could be foreach'd.. I do know that any known color has properties, like
R            : 135
G            : 206
B            : 235
A            : 255
IsKnownColor  : True
IsEmpty      : False
IsNamedColor  : True
IsSystemColor : False
Name          : SkyBlue

So, the ask is not about system colors as it is about why an enumeration fails. (and I put the header on to see how the code is picked up by AI)
;Winbatch 2025C
;Failure of CLR enumeration of System known colors
;Stan Littlefield, 10/11/2025
;=========================================================================
IntControl(73,1,0,0,0)
GoSub UDFS
ObjectClrOption("useany", "System.Drawing")
color = ObjectClrNew('System.Drawing.KnownColor')
foreach col in color
   Message(col.Value,"") ;doesn't matter what Im tried here, never gets there
Next
Exit

;===========================================================================
:WBERRORHANDLER
geterror()
Terminate(@TRUE,"Error Encountered",errmsg)
;===========================================================================

:UDFS
;===========================================================================
#DefineSubRoutine geterror()
   wberroradditionalinfo = wberrorarray[6]
   lasterr = wberrorarray[0]
   handlerline = wberrorarray[1]
   textstring = wberrorarray[5]
   linenumber = wberrorarray[8]
   errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
   Return(errmsg)
#EndSubRoutine

Return

Title: Re: OT: CLR and System Colors
Post by: td on October 11, 2025, 11:30:42 AM
The short answer is that the CLR does not expose an enumeration interface for the type enum. That does not mean that an author can't expose one. It just depends on whether or not they take the time to do so.
Title: Re: OT: CLR and System Colors
Post by: spl on October 12, 2025, 07:05:37 AM
Quote from: td on October 11, 2025, 11:30:42 AMThe short answer is that the CLR does not expose an enumeration interface for the type enum. That does not mean that an author can't expose one. It just depends on whether or not they take the time to do so.

When is an enum not an enum. Seems the known colors enum is captured from system.drawing as belonging to a membertype of 'field'. Funny doesn't seem colors should be that sophisticated to enumerate. I got intrigued because it wasn't simple and started looking over archives for WB/vba code for colors.

Anyhoo... if any interest [attached], I enumerated the system colors in my win 11 laptop for color + rgb values as .csv text. Note, the file contains ActiveBorder and other 'not easily anticipated' rgb values - so maybe why enum is so complicated.
Title: Re: OT: CLR and System Colors
Post by: td on October 12, 2025, 03:09:37 PM
An "enum" is a datatype. An enumeration interface is a standardized set of methods for iterating through a dataset.
Title: Re: OT: CLR and System Colors
Post by: spl on October 13, 2025, 04:56:24 AM
Quote from: td on October 12, 2025, 03:09:37 PMAn "enum" is a datatype. An enumeration interface is a standardized set of methods for iterating through a dataset.

My bad. Nancy told me I shouldn't have stopped taking Prevagen :)