0

I want to be able to make is so that when my program loads it checks to see if the bytes in the file are set to something specific. If they are set to a certain byte then carry out the code.

So I want to be able to make it go to a specific byte, check if it's a certain byte and if it is that certain byte then carry out the code else if it is something else then carry out the other code.

I tried this:

    Dim bytes As Byte() = New Byte(writeStream.Length) {}
    Dim ByteResult As Integer = writeStream.Read(bytes, 30, 1)

    MsgBox(ByteResult)

But it didn't work because for some reason it always returned 1.

I also tried this:

        Dim dataArray(60) As Byte

    If dataArray(30) <> writeStream.ReadByte() - 0 Then
        MsgBox("The bytes have been checked.")
    End If

But that didn't seem to work either because it never opened the message box for me.

For example, I want it to seek to offset 30 and then check if the byte is 00 then I want it to carry out code 1 and else if it is 01 I want it to carry out code2.

Thanks.

avgcoder
  • 372
  • 1
  • 9
  • 27

2 Answers2

0

I found that the following code works:

        fLocation = ("file.txt")

        Dim writeStream As New FileStream(fLocation, FileMode.Open)
        Dim writeBinary As New BinaryWriter(writeStream)

        writeStream.Seek(30, SeekOrigin.Begin)
        Dim ByteResult = writeStream.ReadByte()

        MsgBox(ByteResult)
avgcoder
  • 372
  • 1
  • 9
  • 27
  • I don't see how that can work since BinaryWriter doesn't have a ReadByte method. Perhaps you meant to use BinaryReader? – Chris Dunaway Jun 25 '13 at 14:41
  • I'm not calling the ReadByte method from BinaryWriter but from Filestream. I've written writeStream.ReadByte but I think you read it as writeBinary.ReadByte. – avgcoder Jun 26 '13 at 16:47
0

You can also do this

    Dim FileStream1 As New IO.FileStream("File.txt", IO.FileMode.Open)

    FileStream1.Position = 30
    MsgBox(FileStream1.ReadByte)

    FileStream1.Close()
    FileStream1.Dispose()
David -
  • 2,009
  • 1
  • 13
  • 9
  • That would also do the job, yes. but I think mines easier to understand overall. Yours is nice and short though. – avgcoder Jun 26 '13 at 16:48