Oversætte VB6 til C#
Hejsa.. jeg har to VB6 funktioner, som jeg ikke rigtig kan gennemskue. Er her nogen som kan oversætte dem til pure C# ??Private Sub CreateByteArray(DataText As String, ByRef DataBuffer() As Byte)
Dim i As Long, j As Long, ub As Long
Dim EncodedTextBlock(3) As Byte, DecodedBinaryBlock(2) As Byte
'Strip off the initial TX01 and all of the line feeds
DataText = Replace$(Mid$(DataText, 5), Chr$(10), "")
'Ignore the null termination
ub = Len(DataText) - 1
'Create a data buffer which will include the 4-byte header to begin with
ReDim DataBuffer(((ub + 1) * 3 / 4) - 1)
'Convert each block of 4 encoded text bytes to 3 binary bytes
j = 0
For i = 1 To ub Step 4
EncodedTextBlock(0) = Asc(Mid$(DataText, i, 1)) - 32
EncodedTextBlock(1) = Asc(Mid$(DataText, i + 1, 1)) - 32
EncodedTextBlock(2) = Asc(Mid$(DataText, i + 2, 1)) - 32
EncodedTextBlock(3) = Asc(Mid$(DataText, i + 3, 1)) - 32
DecodeBlock EncodedTextBlock, DecodedBinaryBlock
DataBuffer(j) = DecodedBinaryBlock(0)
DataBuffer(j + 1) = DecodedBinaryBlock(1)
DataBuffer(j + 2) = DecodedBinaryBlock(2)
j = j + 3
Next
'Shift back 4 bytes to strip off the header
ub = UBound(DataBuffer())
For i = 0 To ub - 4
DataBuffer(i) = DataBuffer(i + 4)
Next
'Make DataBuffer the correct size
ReDim Preserve DataBuffer(ub - 4)
End Sub
Private Sub DecodeBlock(ByRef textBlock() As Byte, ByRef binBlock() As Byte)
Dim a(1 To 24) As Integer
'Read out each bit from the text block into the required array position
a(1) = IIf(textBlock(1) And 16, 1, 0)
a(2) = IIf(textBlock(1) And 32, 2, 0)
a(3) = IIf(textBlock(0) And 1, 4, 0)
a(4) = IIf(textBlock(0) And 2, 8, 0)
a(5) = IIf(textBlock(0) And 4, 16, 0)
a(6) = IIf(textBlock(0) And 8, 32, 0)
a(7) = IIf(textBlock(0) And 16, 64, 0)
a(8) = IIf(textBlock(0) And 32, 128, 0)
a(9) = IIf(textBlock(2) And 4, 1, 0)
a(10) = IIf(textBlock(2) And 8, 2, 0)
a(11) = IIf(textBlock(2) And 16, 4, 0)
a(12) = IIf(textBlock(2) And 32, 8, 0)
a(13) = IIf(textBlock(1) And 1, 16, 0)
a(14) = IIf(textBlock(1) And 2, 32, 0)
a(15) = IIf(textBlock(1) And 4, 64, 0)
a(16) = IIf(textBlock(1) And 8, 128, 0)
a(17) = IIf(textBlock(3) And 1, 1, 0)
a(18) = IIf(textBlock(3) And 2, 2, 0)
a(19) = IIf(textBlock(3) And 4, 4, 0)
a(20) = IIf(textBlock(3) And 8, 8, 0)
a(21) = IIf(textBlock(3) And 16, 16, 0)
a(22) = IIf(textBlock(3) And 32, 32, 0)
a(23) = IIf(textBlock(2) And 1, 64, 0)
a(24) = IIf(textBlock(2) And 2, 128, 0)
'Merge the bits back into the binary block
binBlock(0) = a(1) + a(2) + a(3) + a(4) + a(5) + a(6) + a(7) + a(8)
binBlock(1) = a(9) + a(10) + a(11) + a(12) + a(13) + a(14) + a(15) + a(16)
binBlock(2) = a(17) + a(18) + a(19) + a(20) + a(21) + a(22) + a(23) + a(24)
End Sub
kontakt mig evt. på: subtile [nospam] hotmail.com - jeg vil gerne give en lille betaling hvis koden kan bruges...