Hi
I have a ydecoder function that I use in VB6, I need to convert it to run under b4a, I think its fairly straight forward, just need to change a couple of string replace lines, but there is 1 part I have no idea on, so hope somebody can help.
This is the VB6 Function
And this is what I have so far with b4a
Im unsure about the last 2 lines :
Thanks in advance for any help.
Regards
Potman100
I have a ydecoder function that I use in VB6, I need to convert it to run under b4a, I think its fairly straight forward, just need to change a couple of string replace lines, but there is 1 part I have no idea on, so hope somebody can help.
This is the VB6 Function
B4X:
Public Function yDecode(sString As String) As String
Dim bOut() As Byte, bIn() As Byte, bTest As Byte, bEscaped As Boolean, lPos As Long, lChar As Long
sString = Replace(sString, vbCr, vbNullString) 'Get rid of the vbCrLfs. These could be in...
sString = Replace(sString, vbLf, vbNullString) 'either order.
bIn = StrConv(sString, vbFromUnicode) 'Load the input byte array.
ReDim bOut(UBound(bIn)) 'There is no case where the output will be larger.
For lChar = 0 To UBound(bIn)
If bIn(lChar) <> 61 Then
bTest = ((bIn(lChar) + 256) - 42) Mod 256
If bEscaped Then
bTest = ((bTest + 256) - 64) Mod 256
bEscaped = False
End If
bOut(lPos) = bTest
lPos = lPos + 1
Else
bEscaped = True
End If
Next lChar
ReDim Preserve bOut(lPos - 1) 'Truncate the unused portion of the buffer.
yDecode = StrConv(bOut, vbUnicode) 'Convert back to a string and return.
End Function
And this is what I have so far with b4a
B4X:
Sub ydecoder(iData As String) As String
Dim bIn() As Byte, bTest As Byte, bEscaped As Boolean, lPos As Long, lChar As Long
iData = iData.Replace(Chr(10),Null)
iData = iData.Replace(Chr(13),Null)
bIn = iData.GetBytes("UTF-8")
Dim bOut(bIn.Length) As Byte
'*********** NOT SURE IF THIS WILL WORK, BUT I THINK IT WILL ************
For lChar = 0 To bIn.Length
If bIn(lChar) <> 61 Then
bTest = ((bIn(lChar) + 256) - 42) Mod 256
If bEscaped Then
bTest = ((bTest + 256) - 64) Mod 256
bEscaped = False
End If
bOut(lPos) = bTest
lPos = lPos + 1
Else
bEscaped = True
End If
Next lChar
'*********** NOT SURE IF THIS WILL WORK, BUT I THINK IT WILL ************
End Sub
Im unsure about the last 2 lines :
B4X:
ReDim Preserve bOut(lPos - 1) 'Truncate the unused portion of the buffer.
yDecode = StrConv(bOut, vbUnicode) 'Convert back to a string and return.
Thanks in advance for any help.
Regards
Potman100