Imports System
Imports System.IO
Class leerPBM
Public Shared Sub Main(ByVal args As String())
Dim fileName As String
Dim data As String
Dim line As String
Dim width As Integer
Dim height As Integer
Console.WriteLine("Enter the file name: ")
fileName = Console.ReadLine()
If Not fileName.Contains(".pbm") Then fileName += ".pbm"
If Not File.Exists(fileName) Then
Console.WriteLine("File not found!")
Return
End If
Try
Dim myFile As StreamReader = File.OpenText(fileName)
line = myFile.ReadLine()
If line <> "P1" Then
Console.WriteLine("Does not seem a B&W ASCII PBM")
Return
End If
Console.WriteLine("Found B&W ASCII PBM")
line = myFile.ReadLine()
If (line.Length > 1) AndAlso (line(0) = "#"c) Then
Console.WriteLine("Comment: " & line.Substring(1))
line = myFile.ReadLine()
End If
Dim widthheight As String() = line.Split(" "c)
width = Convert.ToInt32(widthheight(0))
height = Convert.ToInt32(widthheight(1))
Console.WriteLine("width: {0}", width)
Console.WriteLine("height: {0}", height)
data = ""
line = myFile.ReadLine()
While line IsNot Nothing
data += line
line = myFile.ReadLine()
End While
myFile.Close()
Catch problem As IOException
Console.WriteLine("File was not read properly")
Console.WriteLine("Details: {0}", problem.Message)
Return
End Try
data = data.Replace(" ", "")
Dim pos As Integer = 0
For Each symbol As Char In data
If pos Mod width = 0 Then Console.WriteLine()
If symbol = "1"c Then
Console.Write("X")
ElseIf symbol = "0"c Then
Console.Write(".")
End If
pos += 1
Next
Console.WriteLine()
End Sub
End Class