KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Convert RGB String to RGB Decimal values
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: June 22, 2012

The following is a utility method that converts an RGB String into RGB Decimal values:

//Method: UTIL_RGBString_To_Decimal
//Parameters: $1 (Text) - RGB string
//            $2 (Pointer) - Pointer to longint R (red) value
//            $3 (Pointer) - Pointer to longint G (green) value
//            $4 (Pointer) - Pointer to longint B (blue) value

C_TEXT($1;$RGBString_t)
C_POINTER($2;$3;$4)
C_TEXT($subString_t)
C_LONGINT($pos_l)

If (Count parameters=4)
   $RGBString_t:=$1

   $subString_t:=Substring($RGBString_t;5)
   $pos_l:=Position(",";$subString_t)
   $2->:=Num(Substring($subString_t;1;$pos_l))

   $subString_t:=Substring($subString_t;$pos_l+1)
   $pos_l:=Position(",";$subString_t)
   $3->:=Num(Substring($subString_t;1;$pos_l))

   $subString_t:=Substring($subString_t;$pos_l+1)
   $4->:=Num(Substring($subString_t;1;Length($subString_t)-1))
End if


Below is an example of how the method can be called:

C_TEXT($RGBString_t)
C_LONGINT($r_l;$g_l;$b_l)

$RGBString_t:="rgb(0,128,192)"
UTIL_RGBString_To_Decimal ($RGBString_t;->$r_l;->$g_l;->$b_l)

//$r_l = 0; $g_l = 128; $b_l = 192