VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts RGB to Long and Long to RGB (Expanded from Anonymous 3/9/1999)

by Michael Hickman (1 Submission)
Category: Graphics
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 2nd September 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts RGB to Long and Long to RGB (Expanded from "Anonymous" 3/9/1999)

Rate Converts RGB to Long and Long to RGB (Expanded from Anonymous 3/9/1999)



on it by making a form to do this for you.  I needed this to _
get my color settings before I had to go to a program like _
Paint or PowerPoint to check my colors and make my settings. _
If you like it, enjoy!  If not, then Oh Well!

'You will need: _
Command1 (Captioned "Reset All to 0"), _
Command2(0) (Cap. "RGB to Long"), _
Command2(1) (Cap. "Long to RGB"), _
Text2 (Text = 0 & Label above "Long"), _
Text1(0) (0 & "R"), _
Text1(1) (0 & "G") and _
Text1(2) (0 & "B")

Private Sub Command1_Click()
'This is the "Reset All to 0"
    Text1(0).Text = 0
    Text1(1).Text = 0
    Text1(2).Text = 0
    Text2.Text = 0
End Sub

Private Sub Command2_Click(Index As Integer)
Select Case Index
    Case 0      'This is the "RGB to Long"
        RGB_COMP
    Case 1      'This is the "Long to RGB"
        LONG_COMP
End Select

End Sub

Private Sub RGB_COMP()
'Because it's 0 to 255, you can't
'be blank (less than 0) or above 255
If Len(Text1(Index).Text) = 0 Then
    Text1(Index).Text = 0
End If
If Text1(Index).Text > 255 Then
    Text1(Index).Text = 255
End If
'This does the math that Anonymous provided us with
Select Case Index
    Case 0
        If Text1(2).Text <> "" Then
            If Text1(1).Text <> "" Then
                Text2.Text = Text1(2).Text * 65536 + Text1(1).Text * 256 + Text1(0).Text
            End If
        End If
    Case 1
        If Text1(2).Text <> "" Then
            If Text1(0).Text <> "" Then
                Text2.Text = Text1(2).Text * 65536 + Text1(1).Text * 256 + Text1(0).Text
            End If
        End If
    Case 2
        If Text1(1).Text <> "" Then
            If Text1(0).Text <> "" Then
                Text2.Text = Text1(2).Text * 65536 + Text1(1).Text * 256 + Text1(0).Text
            End If
        End If
End Select
    B = Text2.Text \ 65536
    G = (Text2.Text - B * 65536) \ 256
    R = Text2.Text - B * 65536 - G * 256
    Text1(0).Text = R
    Text1(1).Text = G
    Text1(2).Text = B
End Sub

Private Sub LONG_COMP()
'Because it's 0 to 16777215, you can't
'be blank (less than 0) or above 16777215
If Len(Text2.Text) = 0 Then
    Text2.Text = 0
End If
If Text2.Text > 16777215 Then
    Text2.Text = 16777215
End If
'This does the math that Anonymous provided us with
    Text1(2).Text = Text2.Text \ 65536
    Text1(1).Text = (Text2.Text - Text1(2).Text * 65536) \ 256
    Text1(0).Text = Text2.Text - Text1(2).Text * 65536 - Text1(1).Text * 256
End Sub

Private Sub Text1_GotFocus(Index As Integer)
'This will select all text on focus
    Text1(Index).SelStart = 0
    Text1(Index).SelLength = Len(Text1(Index).Text)
End Sub

Private Sub Text2_GotFocus()
'This will select all text on focus
    Text2.SelStart = 0
    Text2.SelLength = Len(Text2.Text)
End Sub

Download this snippet    Add to My Saved Code

Converts RGB to Long and Long to RGB (Expanded from Anonymous 3/9/1999) Comments

No comments have been posted about Converts RGB to Long and Long to RGB (Expanded from Anonymous 3/9/1999). Why not be the first to post a comment about Converts RGB to Long and Long to RGB (Expanded from Anonymous 3/9/1999).

Post your comment

Subject:
Message:
0/1000 characters