Importing module

I'm using a vb6 module source code, in a visual basic .net project. The code reads a file in binary mode like this:

Get #1, 5022, S

the #1 is the file that is being used, 5022 is the place, in the file, to start reading and 'S' is a variant variable. This works just fine in vb6, but in vb .net i've tryed this approach:

Microsoft.VisualBasic.FileGet(1, S, 5022)

But it doesn't work!!!
Instead its given an error message
error code: 5
error message (translated to english): "The calls of delayed entailing for the system file methods in visual basic execution time, are not allowed"

I've also tryed to use the BinaryReader with Filestreams but they have one problem which is that the arguments are different. BinaryReader.Read() needs the 'count characters' from the place where he will start reading. Something that 'Get' doesn't need.
what other choices do i have or what can i do to continue to use 'Get' or a similiar function in Visual Basic .net

My thanks in advanced

Comments

  • : I'm using a vb6 module source code, in a visual basic .net project. The code reads a file in binary mode like this:
    :
    : Get #1, 5022, S
    :
    : the #1 is the file that is being used, 5022 is the place, in the file, to start reading and 'S' is a variant variable. This works just fine in vb6, but in vb .net i've tryed this approach:
    :
    : Microsoft.VisualBasic.FileGet(1, S, 5022)
    :
    : But it doesn't work!!!
    : Instead its given an error message
    : error code: 5
    : error message (translated to english): "The calls of delayed entailing for the system file methods in visual basic execution time, are not allowed"
    :
    : I've also tryed to use the BinaryReader with Filestreams but they have one problem which is that the arguments are different. BinaryReader.Read() needs the 'count characters' from the place where he will start reading. Something that 'Get' doesn't need.
    : what other choices do i have or what can i do to continue to use 'Get' or a similiar function in Visual Basic .net
    :
    : My thanks in advanced
    :
    Hi,
    I'm not sure what is the purpose of your application, but to read file by bytes could be done for example in theese two ways
    [code] Dim fs As New FileStream(FileName, FileMode.Open)

    [green]' With StreamReader[/green]
    Dim sr As New StreamReader(fs), CurrentByte As Byte
    While Not sr.EndOfStream
    CurrentByte = CByte(sr.Read)

    [green]'Do something[/green]
    End While


    [green]' Just let the 2nd example works without reopening stream[/green]
    fs.Seek(0, SeekOrigin.Begin)

    [green]' With BinaryReader[/green]
    Dim bs As New BinaryReader(fs)
    CurrentByte = bs.ReadByte()
    While Not CurrentByte < 0
    [green]'Do something[/green]

    CurrentByte = bs.ReadByte()
    End While[/code]
    StreamReader reads entire stream into internal buffer and allows access with .Read (single byte), .Read (buffer), .ReadLine and .ReadToEnd (string - you should (I'd rather use HAVE TO) provider current encoding of text in underlying stream).
    In this case, sr.Position is not working, because position of stream is at the end and reading is provided from internal buffer.

    BinaryStream reads underlaying stream request per request, .Position works and everytime .ReadXXX method is called, only necessary amout of bytes is consumed from underlaying stream.
    For example br.ReadByte consumes 1 byte, br.ReadInteger consumes 4 bytes..

    If you need process whole file and this file is not TOO large (it can be placed into ram without problems) and you everytime need to read byte (not Boolen, Byte, Integer, Double etc..), use StreamReader class.
    It will have better performance.


    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion