![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
hi ,
im making this program that, by using the common color dialog i can select the color and it will return the rgb. it is for a subtitle script (SSA/ASS). so i can generate the colors easier as they work both in hex and plain rgb numbers. i have two option buttons one for the hex color and one for the decimal color, the hex or decimal color appears in a textbox (depending on the option selected). Anyway when i click the other option (when the color is in the text box) it needs to change to hex from decimal (i dont need help with that) but i dont have a clue how to get the hex number to decimal again. could you help me thanks alot |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Try this:
Dim nHex As Integer, nDec As Integer
nHex = Hex(20)
nDec = Val("&H" & nHex) |
|
|
|
|
|
#3 |
|
Expert Programmer
|
RGB Stuff
Sorry do you just want that decimal Heximalizicallified because I believe that will actually produce the wrong colour. Colour selection dialogs return colours as longs, just like constants (vbwhite) and the rgb function. What you need to do is convert the Hex value into a long by means of the rgb function. The hex value will always be 6 characters long, and in the order R G B. The first two characters make up the Red channel (one byte /255), the next two the blue and so on. So what you actually do (sorry Samir... d'oh I mean er... ooble) is:
myvar = "FF0000" 'red
mylong = rgb(val("&H" & mid(myvar,1,2)),val("&H" & mid(myvar,3,2)),val("&H" & mid(myvar,5,2))) |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
hi thanks alot for your replys
![]() one thing though heres the code i used Private Sub Option1_Click() If (Option2.Value = False) Then If (Color = "Hex") Then Dim myvar As String Dim mylong As Long myvar = Text1.Text mylong = RGB(Val("&H" & Mid(myvar, 1, 2)), Val("&H" & Mid(myvar, 3, 2)), Val("&H" & Mid(myvar, 5, 2))) Text1.Text = mylong End If Color = "Dec" End If End Sub Private Sub Option2_Click() If (Option1.Value = False) Then If (Color = "Dec") Then Text1.Text = Hex(Text1.Text) End If Color = "Hex" End If End Sub color is some variable that determines if its hex or dec. but for some reason it turns out to be different like color from color dialog = 14119408 click on hex option and it = D771F0 click decimal again and i get = 15757783 click hex again and i get = F071D7 then decimal again and i get what i started with = 14119408 and so on... this cant be right am i doing something wrong please help thankyou very much |
|
|
|
|
|
#5 |
|
Expert Programmer
|
RGB Problems
The only things I can see in your code are that hex(text1.text) should be hex(val(text1.text)) to prevent any possible run-time errors. Also it'd be better to use a boolean instead of colour.
What's happening is that the colour is being inverted - first click returns the inverse, second click returns the inverted inverse (the original). This is because the colour longs from the colour dialog seem to return RGB as little-endian and not big-endian like HTML colours. All you need to do is reverse your mid statements: mylong = RGB(Val("&H" & Mid(myvar, 5, 2)), Val("&H" & Mid(myvar, 3, 2)), Val("&H" & Mid(myvar, 1, 2))) |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Jan 2005
Posts: 110
Rep Power: 4
![]() |
![]() thanks alot for the replys guys <- that rymes . lol i thought of an easier way ![]() i just set two vars from when i got the color back one hex and one regualar value so i never had to go through those changing problems ![]() thanks again |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|