1. Sivaprakash BKR
  2. PowerBuilder
  3. Tuesday, 11 May 2021 14:38 PM UTC

Hello,

PB 2019 R3

When I read the theme.json file from pb script, I get color code as string, Which I want to set to a static field through pb script... some thing like this in the constructor event of a static field

This.BackColor = go_ac.of_get_theme_value("window","background-color")

Seems we need to convert the string value to int, before assigning.   Any solution available in PB ?

Happiness Always
BKR Sivaprakash

 

Accepted Answer
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Thursday, 13 May 2021 05:51 AM UTC
  2. PowerBuilder
  3. # Permalink

Thanks René Ullrich and John Fauss for your timings and valuable suggestions.   Finally to convert Hexa coded colour value and apply in PB, one need to 

1.  Convert Hexa value to Long      [ Don't use this value ]
2.  Convert Long to RGB                [ Don't use this value too ]
3.  Swap Blue to Red, Red to Blue  [ Use this value ]

Am I right ? 

Happiness Always
BKR Sivaprakash

 

Comment
  1. John Fauss
  2. Thursday, 13 May 2021 18:05 PM UTC
Yes. Swap the JSON Red/Blue hex codes and then convert.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 12 May 2021 14:05 PM UTC
  2. PowerBuilder
  3. # 1

I agree it can be confusing, particularly for those of us translating between PB and JSON.

From what I've seen, JSON encodes an RGB color value like this: #RRGGBB, or as a 32-bit integer in hexadecimal, 0x00RRGGBB. You can see this in the following link:

https://github.com/bahamas10/css-color-names/blob/master/css-color-names.json

The byte ordering is reversed from what we know and expect in PB, where an RGB color value is represented in a 32-bit integer in hexadecimal as 0x00BBGGRR.

Look at the color value for Red in that web page: #ff0000, or 0x00FF0000, In PB, Red is 0x000000FF.

 Thus, Rene is correct in that you must re-order the RR, GG, BB bytes in a JSON color value to be able to properly translate them to a value that PB understands.

Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Wednesday, 12 May 2021 12:06 PM UTC
  2. PowerBuilder
  3. # 2

René Ullrich

Agreed.   My code for conversion

Function of_torgb(value string as_value, ref long al_red, ref long al_green, ref long al_blue)

Long		al_value

al_value = of_tolong(as_value)

al_blue = al_value / 65536
al_value = Mod (al_value, 65536)
al_green = al_value / 256
al_red = Mod (al_value, 256)

Return


Function of_tolong(value string as_hex)

String 		ls_hex	
Integer 	li_loop,li_length
Long 		ll_result = 0

li_length 	= len(as_hex)
ls_hex 		= Upper(as_hex)

FOR li_loop = 1 to li_length																
   ll_result += ( Pos ( '123456789ABCDEF', mid ( ls_hex, li_loop, 1 ) ) * &
						( 16 ^  ( li_length - li_loop ) ) )
NEXT

RETURN ll_result
																			

1.  For #C8D3DF,  I get RGB(223, 211, 200) from the above code, but the site https://www.rapidtables.com/convert/color/hex-to-rgb.html give RGB(200, 211, 223).   Which one is correct?

2.  Setting background color for Window & StaticText object gives two different colors for values #C8D3DF and RGB(223, 211, 200)  or 13161439.  Why ?

Probably somewhere either the code is wrong and the website link is wrong in the conversion.  And / Or the color settings in Powerbuilder for window and static field may also be wrong.  

 

Comment
  1. Sivaprakash BKR
  2. Wednesday, 12 May 2021 13:21 PM UTC
https://www.checkyourmath.com/convert/color/rgb_decimal.php

For RGB(200, 211, 223) the result is 13161439.

When I calculate, 200 + (211*256) + (223*65536), I get 14668744

  1. Helpful
  1. René Ullrich
  2. Wednesday, 12 May 2021 13:28 PM UTC
Powerbuilders RGB function is different.
  1. Helpful
  1. Sivaprakash BKR
  2. Wednesday, 12 May 2021 13:32 PM UTC
We get two different colors when set through hexavalue (#C8D3DF via theme.json) and its long equivalent (13161439 through pb script). Then what's the right way to calculate long equivalent of hex value to set the color?
  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 12 May 2021 11:39 AM UTC
  2. PowerBuilder
  3. # 3

RGB function converts RGB-values into a long value in this way (see help for RGB function):

Red + (256 * Green) + (65536 * Blue)

You see that the Red value is in the lower byte and Blue value in the higher byte.

The color hex value is #RRGGBB. Means the Red value is in the higher byte and blue is in the lower byte.

So you can't simply convert the hex value into Long and use it as PowerBuilder color value!

Instead:

- Extract the R, G and B values from Hex and convert each of it to Integer and use RGB function to get th Long value.

or

- Change the Bytes of Hex value from #RRGGBB to #BBGGRR before you convert it to Long.

 

Example for color Red:

Long: 255 = RGB (255, 0, 0)

Hex: #FF0000

 

correct conversion:

#FF0000: #FF (Red) = 255, #00 (Green) = 0, #00 (Blue) = 0 => RGB (255, 0, 0)

or

#FF0000: => Long (#0000FF)

Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Wednesday, 12 May 2021 10:49 AM UTC
  2. PowerBuilder
  3. # 4

Thanks René Ullrich

I've sent modified project with theme settings.

In the theme.json file I've set the window background color to #C8D3DF, which reflects in Window as Greyish color.

for the two static text field, I've set 

This.Backcolor = RGB(223, 211, 200)   And
This.backcolor = 13161439

Which is not greyish.

Any thing wrong I'm doing?

 

Attachments (1)
Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 12 May 2021 09:04 AM UTC
  2. PowerBuilder
  3. # 5

RGB(200, 211, 223) = 14668744 = #DFD3C8

RGB(223, 211, 200) = 13161439 = #C8D3DF

 

Comment
  1. Sivaprakash BKR
  2. Wednesday, 12 May 2021 11:11 AM UTC
I got the RGB values from this link

https://www.rapidtables.com/convert/color/hex-to-rgb.html

From the above link, for #C8D3DF, the RGB Value is rgb(200, 211, 223) - Which is greyish

  1. Helpful
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Wednesday, 12 May 2021 05:16 AM UTC
  2. PowerBuilder
  3. # 6

I've attached a test application, developed in PB 2019 R3

 

Attachments (1)
Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Wednesday, 12 May 2021 04:25 AM UTC
  2. PowerBuilder
  3. # 7

Thanks John Fauss

Yes, a hexadecimal value to long should do.   I've Chris code [STD Framework] to convert that and it works fine.

The issue is we get different colors on different method of assignment.   

Hex value:  #C8D3DF
To Long:     13161439
To RGB:     RGB(200, 211, 223)

The code

This.BackColor = RGB(200, 211, 223)
This.Backcolor = 13161439

Both the above code gives two different colors.  

What wrong I'm doing?  

Happiness Always
BKR Sivaprakash

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 11 May 2021 15:10 PM UTC
  2. PowerBuilder
  3. # 8

Are you asking how to convert a hexadecimal value in string form to a PB Long datatype?

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.