dcsimg
Results 1 to 25 of 25

Thread: [RESOLVED] VS2015 Question Regarding Stored Colors

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Resolved [RESOLVED] VS2015 Question Regarding Stored Colors

    hey,
    i created in SQL a field(Name) Called ColorTreat AND its datatype is int.
    now i have some questions
    1) i want to pick any color from the color picker and store it
    how do i do that?
    and how will i see it in the database?
    i mean lets say color black ok?
    i will see in the table this = 0,0,0 ?
    how does it store the color?

    i am sure alot of you have done this many times(i never done this before)
    id love to hear and learn from you how youve accomplished that
    appreciate any help from you vb net goros
    regards
    salsa

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,634

    Re: VS2015 Question Regarding Stored Colors

    The Color type has a ToArgb method that returns an Integer. An Integer is 32 bits wide, which is four bytes. Those four bytes represent the alpha, red, green and blue components of the Color. You can store that Integer in your database and then convert it to a Color value by calling Color.FromArgb.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: VS2015 Question Regarding Stored Colors

    how is it stored?(what will i see in the sql field)
    in which way?
    can you show me an example please?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,945

    Re: VS2015 Question Regarding Stored Colors

    You would see a number. The field is an integer. So that's what you would store in it, so that's what you would see.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: VS2015 Question Regarding Stored Colors

    You would see a number. The field is an integer. So that's what you would store in it, so that's what you would see.
    i see.
    so if i want to insert manualy for purpose test a color in the sql field how do i do that?
    like this?
    255255255
    or
    255,255,255 ?

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,349

    Re: VS2015 Question Regarding Stored Colors

    The number could be something like 125435798, and it is not something that you can easily read to work out what the colour is (except for black which is just 0, and anything from 1 to 255 is red).


    For test colours you could use black/red, or you can calculate other values.

    Assuming you know the rgb values you want, you can multiply them and add the results together:
    value = r + (256 * g) + (256 * 256 * b)

    ..so bright green (0,255,0) would be: 0 + (256* 255) + (0) = 65280

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,752

    Re: VS2015 Question Regarding Stored Colors

    Neither. What you are showing there are the byte values for RGB, but an integer won't look like either of those. In Hex, you would see FFFFFF, but most databases would show an integer as a decimal value, since that's what we see. So, for that value you would see 16777215.


    Does that speak to you? Probably not. If you want to see the RGB bytes, then you'd be better off viewing the number in Hex, as every byte would be two characters. Most people who deal with graphics tend to be working with Hex, so you see plenty of charts that show colors in Hex...and possibly RGB, but it's rare to see one in decimal, because there's no clear definition between the bytes in decimal. You can see decimal as Hex using the calculator in Windows, and you may want to.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: VS2015 Question Regarding Stored Colors

    So, for that value you would see 16777215.
    BINGO!!tnx shaggy

    or test colours you could use black/red, or you can calculate other values.

    Assuming you know the rgb values you want, you can multiply them and add the results together:
    value = r + (256 * g) + (256 * 256 * b)

    ..so bright green (0,255,0) would be: 0 + (256* 255) + (0) = 65280
    tnx si

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    why cant i see the color?
    Code:
                    Dim Dr As SqlDataReader
                    If IsDBNull(Dr(9)) Then
                        item.SubItems.Add("").BackColor = Color.White
                    Else
                        item.SubItems.Add("").BackColor = Color.FromArgb(Dr(9))
                    End If

  10. #10

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    i stored this number
    16777215

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,752

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Yeah, but what you stored was the RGB value for 255, 255, 255, or Hex &HFFFFFF, both of which are the same, and all three of which are White, which happens to be your other option. Either way it should be white. Try it with 0, or 255 as a value. The first would be black, what would the second be?
    My usual boring signature: Nothing

  12. #12

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Try it with 0, or 255 as a value. The first would be black, what would the second be?
    what do you mean sir?
    i sotred 0 and 255 nothing appears

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,065

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Quote Originally Posted by salsa31 View Post
    why cant i see the color?
    Code:
                    Dim Dr As SqlDataReader
                    If IsDBNull(Dr(9)) Then
                        item.SubItems.Add("").BackColor = Color.White
                    Else
                        item.SubItems.Add("").BackColor = Color.FromArgb(Dr(9))
                    End If
    Assuming there is code not shown put a breakpoint on the If. What is in Dr(9)? What is its datatype?

    Also, why is this marked as Resolved when it doesn't appear to be?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Dr(9) is an int thats holds the numbers of the stored colors

  15. #15
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,065

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Quote Originally Posted by salsa31 View Post
    Dr(9) is an int thats holds the numbers of the stored colors
    What was the answer to the other question?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  16. #16

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    i marked it by mistake
    why ?

  17. #17
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,065

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Quote Originally Posted by dbasnett View Post
    Assuming there is code not shown put a breakpoint on the If. What is in Dr(9)?
    Do you do this? What is the value?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  18. #18

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    its working now dbasnett
    tnx

  19. #19
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    564

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Does Dr(9) actually retrieve your number from the database? Something like messagebox.show(Dr(9)) will tell you that. Also, what is the control whose backcolor you are setting? I can't get my head around item.SubItems.Add("").BackColor = Color.FromArgb(Dr(9)). Why not put a temporary label on your form and set it's backcolor? Something like label1.backcolor = Color.FromArgb(Dr(9)). Make sure the label actually contains some text so you can see it.

  20. #20
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    564

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Too slow ...

  21. #21
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,752

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Too, slow, but a good point. I wasn't looking at whether the code worked, as I assumed THAT wasn't the question. The point I focused on was that the code, as written, would choose between white and white (since White IS 255,255,255). If changing it to 0 or 255 didn't change the color, then the code itself wasn't working. Showing what was in dr(9) would likely help that, depending on where it was located. The best way to do that would be a breakpoint, because that would allow you to also see whether or not the line that set the color was reached. Whether or not that is even how to color that item, I couldn't say, as that can be a totally different (and sometimes difficult) problem.
    My usual boring signature: Nothing

  22. #22

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    dr(9) = 85616116

  23. #23

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    Quote Originally Posted by paulg4ije View Post
    Too slow ...
    add the rep for u

  24. #24
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,652

    Re: VS2015 Question Regarding Stored Colors

    Quote Originally Posted by Shaggy Hiker View Post
    Neither. What you are showing there are the byte values for RGB, but an integer won't look like either of those. In Hex, you would see FFFFFF, but most databases would show an integer as a decimal value, since that's what we see. So, for that value you would see 16777215.
    ...
    If you used the .toArgb method that jmcilhinney mentioned, then you shouldn't see 16777215, you should see -1 because the Alpha byte would also be FF, e.g. Color.White.toArgb.toString("X") will display FFFFFFFF.

    I thought that might be what the problem was, that the conversion was leaving the alpha with a 0 value, so he wasn't seeing the color (it was fully transparent), but perhaps that wasn't the issue.

  25. #25

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,718

    Re: [RESOLVED] VS2015 Question Regarding Stored Colors

    hey passel the color was white on a listview thats white
    thats why i didnt see it lol
    i used this
    Code:
    Color.FromArgb(Dr(9))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width