Forum Discussion

Romans_I_XVI's avatar
Romans_I_XVI
Roku Guru
11 years ago

How do I save a hex value to the registry?

I'd like to store some hex values in the registry, however the registry only accepts strings. I can't use .tostr() and then back to .toint() because the value is too large as explained by RokuKC here -> viewtopic.php?f=34&t=84652 .

So what are my options? How would I store a hex value (being used for a color such as &hffffffff) in the registry?

Thanks.

3 Replies

  • I'm doing this:

    sec.Write("bakclr", "&h404040FF")
    background = HexToInteger( sec.Read("bakclr"))
  • Try Stri(int) in one direction and then val(str, 10) in the other.
    (Yes, the val with second argument.)

    Hex colors with R>127 are negative int-s - that's ok as long as conversion to and fro is faithful.

    PS. a quick&dirty check (besides discovering a bug in loops) seems to confirm the combo working:
    BrightScript Debugger> for v = -2^31 to 2^31-258 step 257: check = v=val(stri(v), 10) or 0/0: next
    BrightScript Debugger> REM: no "divide by zero" error

    As illustration to what happens to big ints when they go through floats:
    BrightScript Debugger> b = &h7ffffeff
    BrightScript Debugger> ? b = int(b)
    false
    BrightScript Debugger> ? type(b), b, int(b), cint(b)
    Integer 2147483391 2147483392 2147483392
  • Thanks for your responses, after I posted this I decided even if I got those numbers into the registry it wouldn't give me the ability to easily adjust the color like I needed. So I got this put together, now I will just save the hue to the registry, which is only a max of 360 anyway 😄 .
    viewtopic.php?f=34&t=85620