I'm currently converting VB6 to C#. Can you help me convert this code?
Here's the VB6 code:
'This converts the bytes into test parameters
Sub getParamValues(ByRef TransData() As Byte, ByRef testparam() As Single, startbyte As Integer)
Dim tmpdata As bByteType
Dim convertedvalue As SingleType
Dim i As Integer
Dim bytecounter As Integer
bytecounter = startbyte
'On Error Resume Next
For i = 0 To 9
tmpdata.bBytes(0) = TransData(bytecounter + 3) 'TransData(0 + 3)
tmpdata.bBytes(1) = TransData(bytecounter + 2) 'TransData(0 + 2)
tmpdata.bBytes(2) = TransData(bytecounter + 1) 'TransData(0 + 1)
tmpdata.bBytes(3) = TransData(bytecounter) 'TransData (0)
'THIS CODE I WANT TO CONVERT
LSet convertedvalue = tmpdata
testparam(i) = convertedvalue.dResult 'Gets the test parameters
bytecounter = bytecounter + 4
Next i
End Sub
and this
Private Type bByteType
bBytes(3) As Byte
End Type
Private Type SingleType
dResult As Single
End Type
I tried my best to convert this into C#. But I'm getting a NullException. I just can't convert the Type
from Vb6 into C#. So, I tried struct
. But I have no idea how to transfer the bBytes
data into tmpdata
using C#.
public void getParamValues(ref byte[] TransData, ref Single[] testparam, int startbyte)
{
bByteType tmpdata = new bByteType();
SingleType convertedvalue = new SingleType();
//byte[] bBytes = new byte[4];
int bytecounter = 0;
bytecounter = startbyte;
for (int i = 0; i < 9; i++)
{
tmpdata.bBytes[0] = TransData[bytecounter + 3];
tmpdata.bBytes[1] = TransData[bytecounter + 2];
tmpdata.bBytes[2] = TransData[bytecounter + 1];
tmpdata.bBytes[3] = TransData[bytecounter];
//LSet convertedvalue = tmpdata <--- Supposed to convert to C#
testparam[i] = convertedvalue.dResult;
bytecounter = bytecounter + 4;
}
}
public struct bByteType
{
//byte[] bBytes = new byte[3];
public byte[] bBytes;
public bByteType(byte[] size)
{
bBytes = new byte[4];
}
}
struct SingleType
{
public Single dResult;
}