cannot read file

M

martins

Hi,

I cannot make this VB6 code to work in VB.NET.

Dim buffer As String
Dim tmp_i As Long

Open FileName For Binary Access Read As #1
buffer = Input(FileLen(FileName), #1)
tmp_i = FileLen(FileName)
Close #1


I tried this :

Dim buffer As String
Dim tmp_i As integer

Dim idF As Integer = FreeFile()
FileOpen(idF, FileName, OpenMode.Binary, OpenAccess.Read)
Input(idF, buffer)
tmp_i = FileLen(FileName)
FileClose(idF)


but it doesn't read the file to the end...the resulting buffer lenght in VB6
is different

How can I read a binary file into a string type buffer ?
 
S

Stephany Young

Try:

Dim _sr As New System.IO.StreamReader(FileName)

Dim _buffer As String = _sr.ReadToEnd()

_sr.Close

Dim _i As Int32 = _buffer.Length
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top