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. Any help would be greatly
appreciated!!!!
Public Function SetBinaryLengthofMsg(ByRef iLen As Integer, ByRef
iPosLen As Integer) As String
iLen = decimal length value to be converted to binary
iPosLen = 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(Chr(iNum))
lTmpLenVal = lTmpLenVal Mod 256
Case 1
iNum = lTmpLenVal
sb.Append(Chr(iNum))
End Select
Next iLoop
'---return length value in binary hex
SetBinaryLengthofMsg = sb.ToString()
End Function
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. Any help would be greatly
appreciated!!!!
Public Function SetBinaryLengthofMsg(ByRef iLen As Integer, ByRef
iPosLen As Integer) As String
iLen = decimal length value to be converted to binary
iPosLen = 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(Chr(iNum))
lTmpLenVal = lTmpLenVal Mod 256
Case 1
iNum = lTmpLenVal
sb.Append(Chr(iNum))
End Select
Next iLoop
'---return length value in binary hex
SetBinaryLengthofMsg = sb.ToString()
End Function