// Function to set the color from a color code string void setColorByCode(string inCode){ // Set the value in the CODE field setCodeField(inCode); // Remove leading "#" if present if(startsWith(inCode, "#")){ inCode = cropText(inCode, 1, countText(inCode)); } // Add hexadecimal prefix inCode = "0x" + inCode; // Validate the string as hexadecimal if(isHex(inCode)){ // Convert to int int code = inCode; // Check if it's within the valid color code range if(0<=code && code<=0xffffff){ // Generate a color array int color[] = color(code); // Apply the color to the display panel setDisplayColor(color); // Set values in the RED/GREEN/BLUE fields setRgbField( (string)color[0], (string)color[1], (string)color[2] ); }else{ alert("The CODE value is outside the valid range of #000000 to #ffffff."); } }else{ alert("The CODE value is not a valid hexadecimal number."); } }