Reading a binay file (2 - GIF) Learn programming Visual Basic (


File Management


Reading a binay file (2 - GIF)


Create a Visual Basic ( program to check if a GIF image file seems to be correct.

It must see if the first four bytes are G, I, F, 8.

In case it seems correct, it must also display the GIF version (87 or 89), checking if the following byte is a 7 or a 9.


Imports System
Imports System.IO
Public Class GifFile
    Public Shared Sub Main()
        Dim data As Byte() = New Byte(4) {}
        Dim file As BinaryReader = New BinaryReader(File.Open("test.gif", FileMode.Open))

        For i As Integer = 0 To 5 - 1
            data(i) = file.ReadByte()


        If data(0) = Convert.ToByte("G"c) AndAlso data(1) = Convert.ToByte("I"c) AndAlso data(2) = Convert.ToByte("F"c) AndAlso data(3) = Convert.ToByte("8"c) Then
            Console.WriteLine("Its a GIF8" & data(4))
            Console.WriteLine("It not gif file")
        End If
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.