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

Lesson:

Functions


Exercise:

Function write underlined


Objetive:

Create a function able to write centered on screen the text that is indicated as a parameter (supposing a screen width of 80 characters) and then underline it (writing several hyphens under that word):

WriteUnderlined("Hello!");


Code:

Imports System
Public Class exercise102
    Public Shared Sub WriteUnder(ByVal text As String)
        Dim countSpaces As Integer = (80 - text.Length) / 2
        Dim i As Integer = 0

        While i < countSpaces
            Console.Write(" ")
            i += 1
        End While

        Console.WriteLine(text)

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

        For i = 0 To text.Length - 1
            Console.Write("_")
        Next
    End Sub

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

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