file manipulation from vb6

Hi everyone!
I am still converting this vb6 project.
I got to the following code:

[code] Dim fileNum As Integer
Dim fileLength As Integer
Dim bytes() As Byte
Dim data As Byte
Dim i As Integer

fileNum = FreeFile
Open “C:\ECONTROL\PKI\archivo.pfx” For Binary As fileNum
fileLength = LOF(fileNum)
ReDim bytes(fileLength)
i = 0
Do While Not EOF(fileNum)
Get fileNum, , data
bytes(i) = data
i = i + 1
Loop
Close fileNum[/code]

Could some one give a hand on this? thank you!

do you really need to get an array of bytes ?

otherwise this is really short

  dim f as new folderItem ("C:\\ECONTROL\\PKI\\archivo.pfx", FolderItem.PathTypeAbsolute)
  dim bs as BinaryStream = BinaryStream.Open(f)
  dim mb as MemoryBlock = bs.Read( bs.Length() )

i need that byte array to send as a parameter to another function…

the byte array is easy to create by looping over the memoryblock and reading the bytes out
or you can read them one by one from the binary stream

personally I’d look over the code and use a memoryblock as it basically IS an array of bytes or at least can be manipulated as such

but, how many loops?

if i do as follows:

For i = 0 to bs.Length() - 1 bytes.Append(mb(i)) next bs

is the result from " bs.Length() " in numer of bytes?

did you try it? best way to learn things is to attempt to do them, then ask why it did or did not work as you expected…

next i, sorry!

Are you sure you want an array of bytes? It’s not the same thing as a byte array. That’s more of a memoryblock.

dim f as new folderItem (“C:\ECONTROL\PKI\archivo.pfx”, FolderItem.PathTypeAbsolute)
dim bs as BinaryStream = BinaryStream.Open(f)
dim mb as MemoryBlock = bs.Read( bs.Length() )
bs = nil
f = nil
dim bytes() as Byte
for i as integer = 0 to mb.Size-1
bytes.append mb.byte(i)
next