Function write centered Learn programming Visual Basic (VB.net)

Lesson:

Functions


Exercise:

Function write centered


Objetive:

Create a function to write centered on screen the text that is indicated as a parameter (supposing a screen width of 80 characters):

WriteCentered("Hello!");


Code:

Imports System
Public Class exercise101
    Public Shared Sub WriteCentered(ByVal text As String)
        Dim i As Integer = 0

        While i < 17
            Console.WriteLine()
            i += 1
        End While

        For i = 0 To 36 - 1
            Console.Write(" ")
        Next

        Console.Write(text)

        For i = 0 To 14 - 1
            Console.WriteLine()
        Next
    End Sub

    Public Shared Sub Main()
        WriteCentered("Hello")
    End Sub
End Class

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