Ja ich bin folgendermaßen auf den Trichter gekommen, weil ich in VB einen Quellcode habe der mit einem Server komuniziert.
Das wollte ich eigentlich zum größten Teil so übernehmen und auf Delphi halt anpassen.
Und jetzt habe ich eine Function fertig jetzt fängt das ganze spielchen wieder von vorne.
Ich habe nämlich noch mehr functionen die ich brauche:
Code:
Public Function StringToHex(sMessage As String) As String
Dim i As Integer
Dim sHex As String
For i = 1 To Len(sMessage)
sHex = Hex(Asc(Mid(sMessage, i, 1)))
If Len(sHex) < 2 Then sHex = String(2 - Len(sHex), "0") & sHex
StringToHex = StringToHex & sHex
Next
End Function
Public Function LongToUnsigned(value As Long) As Double
If value < 0 Then
LongToUnsigned = value + 4294967296#
Else
LongToUnsigned = value
End If
End Function
Public Function HexToString(sMessage As String) As String
Dim i As Integer
For i = 1 To Len(sMessage) Step 2
HexToString = HexToString & Chr(Int("&h" & Mid(sMessage, i, 2)))
Next
End Function
Private Function longToHex(l As Long) As String
longToHex = Hex(l)
If Len(longToHex) < 4 Then longToHex = String(4 - Len(longToHex), "0") & longToHex
longToHex = Right(longToHex, 2) & Left(longToHex, 2)
End Function
Private Function HexToDec(HexNumber As String) As String
Dim i As Long
Dim sHexChar As String
Dim lLength As Long
Dim lPosiValue As Double
Dim Number As Double
lLength = Len(HexNumber)
For i = lLength To 1 Step -1
sHexChar = Mid(HexNumber, i, 1)
lPosiValue = HexToDecChart(sHexChar) * (16 ^ (lLength - i))
Number = Number + lPosiValue
Next
HexToDec = Number
End Function
Private Function HexToBinChart(HexCode As String) As String
Select Case UCase(HexCode)
Case "0": HexToBinChart = "0000"
Case "1": HexToBinChart = "0001"
Case "2": HexToBinChart = "0010"
Case "3": HexToBinChart = "0011"
Case "4": HexToBinChart = "0100"
Case "5": HexToBinChart = "0101"
Case "6": HexToBinChart = "0110"
Case "7": HexToBinChart = "0111"
Case "8": HexToBinChart = "1000"
Case "9": HexToBinChart = "1001"
Case "A": HexToBinChart = "1010"
Case "B": HexToBinChart = "1011"
Case "C": HexToBinChart = "1100"
Case "D": HexToBinChart = "1101"
Case "E": HexToBinChart = "1110"
Case "F": HexToBinChart = "1111"
End Select
End Function
Private Function HexToDecChart(HexCode As String) As Long
Select Case UCase(HexCode)
Case "0": HexToDecChart = 0
Case "1": HexToDecChart = 1
Case "2": HexToDecChart = 2
Case "3": HexToDecChart = 3
Case "4": HexToDecChart = 4
Case "5": HexToDecChart = 5
Case "6": HexToDecChart = 6
Case "7": HexToDecChart = 7
Case "8": HexToDecChart = 8
Case "9": HexToDecChart = 9
Case "A": HexToDecChart = 10
Case "B": HexToDecChart = 11
Case "C": HexToDecChart = 12
Case "D": HexToDecChart = 13
Case "E": HexToDecChart = 14
Case "F": HexToDecChart = 15
End Select
End Function
Wenn ich die jetzt alle in Delphi umschreibe bin ich alt und grau.
Deshalb das mit der
DLL, da ich den Code ja habe nur halt in VB.