用户登录  |  用户注册
首 页源码下载网络学院最新源码源码排行屏蔽广告
当前位置:新兴网络 > 网络学院 > 编程开发 > Visual Basic

将网页颜色值转换为VB颜色值的函数

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2011-02-04 13:27:15

将网页颜色值转换为VB颜色值的函数,同时支持颜色名称转换。

VBScript code复制代码
Public Function WebColorToVBColor(WebColor As String) As Long
    Dim strhex As String, R As Double, G As Double, B As Double
    If InStr(WebColor, "#") = 0 Then
        Select Case VBA.LCase(WebColor)
            Case "black": WebColor = "#000000"
            Case "green": WebColor = "#008000"
            Case "silver": WebColor = "#c0c0c0"
            Case "lime": WebColor = "#00ff00"
            Case "gray": WebColor = "#808080"
            Case "olive": WebColor = "#808000"
            Case "white": WebColor = "#ffffff"
            Case "yellow": WebColor = "#ffff00"
            Case "maroon": WebColor = "#800000"
            Case "navy": WebColor = "#000080"
            Case "red": WebColor = "#ff0000"
            Case "blue": WebColor = "#0000ff"
            Case "purple": WebColor = "#800080"
            Case "teal": WebColor = "#008080"
            Case "fuchsia": WebColor = "#ff00ff"
            Case "aqua": WebColor = "#00ffff"
            Case Else: WebColor = "#000000"
        End Select
    End If

    strhex = Trim$(Replace$(WebColor, "#", ""))
    R = CHex(Left$(strhex, 2))
    G = CHex(Right$(Left$(strhex, 4), 2))
    B = CHex(Right$(strhex, 2))

    WebColorToVBColor = RGB(R, G, B)
End Function

Private Function CHex(H) As Double
    Dim Hv, Dv, D, m
    H = UCase$(H)
    For m = 1 To Len(H)
        Hv = Left$(Right$(H, m), 1)
        Select Case Hv
            Case "A"
            Dv = 10
            Case "B"
            Dv = 11
            Case "C"
            Dv = 12
            Case "D"
            Dv = 13
            Case "E"
            Dv = 14
            Case "F"
            Dv = 15
            Case Else
            Dv = Hv
        End Select
        D = D + (Dv * (16 ^ (m - 1)))
    Next
    CHex = D
End Function
附件下载.rar

Tags:颜色值 VB 网页颜色 转换

作者:佚名
  • 好的评价 如果您觉得此文章好,就请您
      100%(1)
  • 差的评价 如果您觉得此文章差,就请您
      0%(0)

网络学院评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论