Converting C++ program to VB.NET
Hi everyone,
I'm converting a program from C++ to VB.NET (2003) for work. I have 90% of it done, but one function has me stumped. Here's the C++ code:
Code:
int ReadPickJc5 ()
{
unsigned long i, j, ulBytes;
char * pPick, g_pByteInputPick ;
ulBytes = (g_design.ulInputYarns + 7) / 8;
pPick = (char*)malloc (ulBytes);
if (pPick == NULL)
{
return 1;
}
if ( fread (pPick, 1, ulBytes, inFile) != ulBytes)
{
free (pPick);
return 1;
}
for (i=0; i<ulBytes; i++)
{
for (j=0; j<8; j++)
{
if ((i*8 + j) >= g_design.ulInputYarns) break;
*(g_pByteInputPick + i*8 + j) = BitToByte (*(pPick + i), j);
}
}
free (pPick);
return 0;
}
Here's what I've got so far in vb.net:
Code:
Public Function ReadPickJc5() As Int32
Dim i, j, ulBytes As Long
Dim pPick As ArrayList = New ArrayList
Dim counter As Int32 = 0
Dim tempPickReturned As ArrayList = New ArrayList
ulBytes = (g_design.ulInputYarns + 7) / 8
counter = 0
While (counter < ulBytes)
pPick.Add(bRead.ReadByte())
counter += 1
End While
i = 0
While (i < ulBytes)
j = 0
While (j < 8)
If ((i * 8 + j) >= g_design.ulInputYarns) Then
Exit While
End If
'The commented line below is really confusing me:
'tempPickReturned.Item(i * 8 + j) = BitToByte(pPick(i), j)
j += 1
End While
i += 1
End While
End Function
Public Function BitToByte(ByVal thisByte As Byte, ByVal shiftValue As Int32) As Byte
Dim reply As Byte
reply = Convert.ToByte(thisByte >> shiftValue)
reply = reply And 1
Return reply
End Function
Any help would be appreciated greatly!