Code worked fine in VB6 but not .NET

  • Thread starter Thread starter Chad Dalton
  • Start date Start date
C

Chad Dalton

The code worked perfectly fine in VB6 for converting a decimal length to
binary hex, but in .NET it only works when the iNum variable doesn't
contain a zero. If zero is passed in then I lose everything in the
string. Does anyone
know how to make the Chr(0) Function work exactly as it did in VB 6. If
you pass 342,2 as the arguments then everything works fine, but if you
pass 54,2 then it returns blank. Your help would be greatly
appreciated!!!!

Public Function SetBinaryLengthofMsg(ByRef lLen As Integer, ByRef
lPosLen As Integer) As String

lLen = decimal length value to be converted to binary
lPosLen = number of bytes in which to store binary length value (max
bytes = 3)

Dim iNum As Integer
Dim iRemainder As Short
Dim iLoop As Short
Dim lTmpLenVal As Integer
Dim szTmpLenString As String
Dim sb As New StringBuilder


'---set temporary decreasing value to length value
lTmpLenVal = lLen
szTmpLenString = ""

'---loop backwards breaking out length value into bytes
For iLoop = lPosLen To 1 Step -1

Select Case iLoop
Case 3
iNum = Int(lTmpLenVal / 65536)
sb.Append(Chr(iNum))
lTmpLenVal = lTmpLenVal Mod 65536
Case 2
iNum = Int(lTmpLenVal / 256)
sb.Append(Microsoft.VisualBasic.Chr(iNum))
lTmpLenVal = lTmpLenVal Mod 256
Case 1
iNum = lTmpLenVal
sb.Append(Microsoft.VisualBasic.Chr(iNum))
End Select

Next iLoop

'---return length value in binary hex
SetBinaryLengthofMsg = sb.ToString()


End Function
 
Back
Top