GetColorRef

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,016
Location
Cambridge, UK
Programming Experience
5-10
This has been bothering me for some time. Does anyone know how to get the GetColorRef Macro to work in VB.Net. Documentation is poor on this subject and i only have a C# example that i can't get to work in VB.Net. Forget the online converters, free or otherwise. As they don't seem to work. I'm not totally sure but it's almost as if bit shifting works differently in VB.Net, but as my C# is ok at best i can't be sure. Here it is. I appreciate any responses. Here's the C#....

VB.NET:
public static int GetColorRef(int r, int g, int b)
}
return (((byte) r) | ((byte) g) << 8)) | (((byte) b) << 0x10));
}


P.s I know i can use the ColorTranslator.ToWin32 and this is a bit of pointless excercise but i would just like to see it work. Call it a challenge:)
 
What you posted didn't add up with paranthesis and such trivialities, but this code give same result as ColorTranslator.ToWin32:​
VB.NET:
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Shared [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] GetColorRef([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] r [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] g [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] Integer[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] b [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]  Return[/COLOR][/SIZE][SIZE=2] ((r) [/SIZE][SIZE=2][COLOR=#0000ff]Or[/COLOR][/SIZE][SIZE=2] (g << 8) [/SIZE][SIZE=2][COLOR=#0000ff]Or[/COLOR][/SIZE][SIZE=2] (b << &H10))[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
 
Back
Top