More Learn programming Visual Basic (VB.net)



Lesson:

File Management


Exercise:

More


Objetive:

Create a program which behaves like the Unix command "more": it must display the contents of a text file, and ask the user to press Enter each time the screen is full.

As a simple approach, you can display the lines truncated to 79 characters, and stop after each 24 lines


Code:

Imports System
Imports System.IO
Namespace More
    Class Program
        Private Shared Sub Main(ByVal args As String())
        End Sub

        Public Sub ShowData(ByVal urlFile As String)
            Dim fichero As StreamReader = New StreamReader(urlFile)
            Dim line As String
            Dim count As Integer = 0

            Do
                line = fichero.ReadLine()

                If line IsNot Nothing Then
                    If count Mod 24 = 0 Then Console.ReadLine()
                    If line.Length > 79 Then line = line.Substring(0, 79)
                    Console.WriteLine(line)
                End If

                count += 1
            Loop While line IsNot Nothing

            fichero.Close()
        End Sub
    End Class
End Namespace



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