«

»

Aug
06

Visual Basic 6 – Dezimal nach Hexadezimal und Dezimalzahlen in Hexadezimalzahlen konvertieren

' /**
' Konvertiert Dezimal Zahlen in Hex
' **/
Public Property Get pDec2Hex(lDec As Long, Optional ByVal lLength As Long = 4, Optional sPrefix As String = "0x") As String
  Dim sHex    As String
  Dim lHexLen As Long

  sHex = Hex(lDec)

  lHexLen = Len(sHex)

  If lLength < 0 Then lLength = 0

  If lHexLen < lLength Then
    sHex = String(lLength - lHexLen, "0") & sHex
  End If

  sHex = sPrefix & sHex

  pDec2Hex = sHex
End Property

' /**
' Hexadezimal nach Dezimal
' @bug: Es werden alle Zeichen in sHex verarbeitet bis zum zeichen ende oder zum ersten ungültigen Zeichen.
'       Beispiel: "0xFFz" ergibt 255
' **/
Public Property Get pHex2Dec(ByVal sHex As String, Optional sPrefix As String = "0x") As Long
  Dim lPrefix As Long

  lPrefix = Len(sPrefix)

  If Left(sHex, lPrefix) = sPrefix Then
    sHex = Mid(sHex, lPrefix + 1)
  End If

  On Local Error Resume Next

  pHex2Dec = CLng(Val("&H" & sHex))
End Property

Hinterlasse eine Antwort

Ihre E-Mail-Adresse wird nicht veröffentlicht.

Sie können diese HTML-Tags verwenden: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

What is 3 + 2 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)