[英]Using LSet from VB6 to C#?
我目前正在將 VB6 轉換為 C#。 你能幫我轉換這個代碼嗎?
這是VB6代碼:
'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
和這個
Private Type bByteType
bBytes(3) As Byte
End Type
Private Type SingleType
dResult As Single
End Type
我盡力將其轉換為 C#。 但我得到一個 NullException。 我只是無法將Type
從 Vb6 轉換為 C#。 所以,我嘗試了struct
。 但我不知道如何使用 C# 將bBytes
數據傳輸到tmpdata
。
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.