here's something far more easier
Yeah fox, i knew you knew but i you could have got a point for it too if you mentioned it :)
Code:
Property Get adh(data() As Byte, length As Long, Optional offset As Long) As String
Dim a() As Byte, y&, x&
ssize(a) = length * 3
For x = offset To offset + length - 1
a(y) = data(x) \ 16 + 48
If a(y) > 57 Then a(y) = a(y) + 7
y = y + 1
a(y) = (data(x) And 15) + 48
If a(y) > 57 Then a(y) = a(y) + 7
y = y + 1
a(y) = 32
y = y + 1
Next x
adh = StrConv(a, vbUnicode)
End Property
1. What does it do? max 3 points
2. Explain my code. max 5 points
3. How can it be impooved? X points
Re: here's something far more easier
Code:
adh is the Property that returns the String
Property Get adh(data() As Byte, length As Long, Optional offset As Long) As String
k Declares a Bytearray to temporarily Store the Hex string
Dim a() As Byte, y&, x&
ssize(a) = length * 3 <--- For Each Original Byte allocates 3 Characters for the Output String
For x = offset To offset + length - 1 'From Starting Point to the end
a(y) = data(x) \ 16 + 48 '48 -- Chr(48) is 0 Lowest Hex Digit
If a(y) > 57 Then a(y) = a(y) + 7 --Chr(57) is 9 the Last Numeric Hex Digit and adding 7 to it will skip to Alphabets instead of :;<=>?@
y = y + 1
a(y) = (data(x) And 15) + 48
If a(y) > 57 Then a(y) = a(y) + 7
y = y + 1
a(y) = 32 'add a Space to Separate it from the Next Set
y = y + 1
Next x
adh = StrConv(a, vbUnicode) 'Convert the Byte array to String
End Property
Re: here's something far more easier
This code doesn't make much sense:
Code:
Property Get adh(data() As Byte, length As Long, Optional offset As Long) As String
Dim a() As Byte, y&, x&
ssize(a) = length * 3 'you're assigning a value to a function
For x = offset To offset + length - 1 'if offset isn't used when the function is called this may produce
'unexpected results
a(y) = data(x) \ 16 + 48
If a(y) > 57 Then a(y) = a(y) + 7
y = y + 1 'y isn't assigned a starting value
a(y) = (data(x) And 15) + 48
If a(y) > 57 Then a(y) = a(y) + 7
y = y + 1
a(y) = 32
y = y + 1
Next x
adh = StrConv(a, vbUnicode)
End Property
>edited: I forgot to remove an unneccesary comment.<