Banner Learn programming Visual Basic (VB.net)

Lesson:

Arrays, Structures and Strings


Exercise:

Banner


Objetive:

Create a Visual Basic (VB.net) program to imitate the basic Unix SysV "banner" utility, able to display big texts.


Code:

Imports System
Public Class exercise87
    Private Shared Sub Main(ByVal args As String())
        Dim esqueleto As String() = {"         ###  ### ###  # #   ##### ###   #  ##     ###  ", "         ###  ### ###  # #  #  #  ## #  #  #  #    ###  ", "         ###   #   # ########  #   ### #    ##      #   ", "          #            # #   #####    #    ###     #    ", "                     #######   #  #  # ####   # #       ", "         ###           # #  #  #  # #  # ##    #        ", "         ###           # #   ##### #   ### #### #       ", "   ##    ##                                            #", "  #        #   #   #    #                             # ", " #          #   # #     #                            #  ", " #          # ####### #####   ###   #####           #   ", " #          #   # #     #     ###           ###    #    ", "  #        #   #   #    #      #            ###   #     ", "   ##    ##                   #             ###  #      ", "  ###     #    #####  ##### #      ####### ##### #######", " #   #   ##   #     ##     ##    # #      #     ##    # ", "#     # # #         #      ##    # #      #          #  ", "#     #   #    #####  ##### #    # ###### ######    #   ", "#     #   #   #            ########      ##     #  #    ", " #   #    #   #      #     #     # #     ##     #  #    ", "  ###   ##### ####### #####      #  #####  #####   #    ", " #####  #####    #     ###      #           #     ##### ", "#     ##     #  ###    ###     #             #   #     #", "#     ##     #   #            #     #####     #        #", " #####  ######         ###   #                 #     ## ", "#     #      #   #     ###    #     #####     #     #   ", "#     ##     #  ###     #      #             #          ", " #####  #####    #     #        #           #       #   ", " #####    #   ######  ##### ###### ############## ##### ", "#     #  # #  #     ##     ##     ##      #      #     #", "# ### # #   # #     ##      #     ##      #      #      ", "# # # ##     ####### #      #     ######  #####  #  ####", "# #### ########     ##      #     ##      #      #     #", "#      #     ##     ##     ##     ##      #      #     #", " ##### #     #######  ##### ###### ########       ##### ", "#     #  ###        ##    # #      #     ##     ########", "#     #   #         ##   #  #      ##   ####    ##     #", "#     #   #         ##  #   #      # # # ## #   ##     #", "#######   #         ####    #      #  #  ##  #  ##     #", "#     #   #   #     ##  #   #      #     ##   # ##     #", "#     #   #   #     ##   #  #      #     ##    ###     #", "#     #  ###   ##### #    # ########     ##     ########", "######  ##### ######  ##### ########     ##     ##     #", "#     ##     ##     ##     #   #   #     ##     ##  #  #", "#     ##     ##     ##         #   #     ##     ##  #  #", "###### #     #######  #####    #   #     ##     ##  #  #", "#      #   # ##   #        #   #   #     # #   # #  #  #", "#      #    # #    # #     #   #   #     #  # #  #  #  #", "#       #### ##     # #####    #    #####    #    ## ## ", "#     ##     ######## ##### #       #####    #          ", " #   #  #   #      #  #      #          #   # #         ", "  # #    # #      #   #       #         #  #   #        ", "   #      #      #    #        #        #               ", "  # #     #     #     #         #       #               ", " #   #    #    #      #          #      #               ", "#     #   #   ####### #####       # #####        #######", "  ###                                                   ", "  ###     ##   #####   ####  #####  ###### ######  #### ", "   #     #  #  #    # #    # #    # #      #      #    #", "        ###### #    # #      #    # #      #      #  ###", "    #   #    # #####  #      #    # #####  #####  #     ", "        #    # #    # #    # #    # #      #      #    #", "        #    # #####   ####  #####  ###### #       #### ", "                                                        ", " #    #    #        # #    # #      #    # #    #  #### ", " #    #    #        # #   #  #      ##  ## ##   # #    #", " ######    #        # ####   #      # ## # # #  # #    #", " #    #    #        # #  #   #      #    # #  # # #    #", " #    #    #   #    # #   #  #      #    # #   ## #    #", " #    #    #    ####  #    # ###### #    # #    #  #### ", "                                                        ", " #####   ####  #####   ####   ##### #    # #    # #    #", " #    # #    # #    # #         #   #    # #    # #    #", " #    # #    # #    #  ####     #   #    # #    # #    #", " #####  #  # # #####       #    #   #    # #    # # ## #", " #      #   #  #   #  #    #    #   #    #  #  #  ##  ##", " #       ### # #    #  ####     #    ####    ##   #    #", "                       ###     #     ###   ##    # # # #", " #    #  #   # ###### #        #        # #  #  # # # # ", "  #  #    # #      #  #        #        #     ## # # # #", "   ##      #      #  ##                 ##        # # # ", "   ##      #     #    #        #        #        # # # #", "  #  #     #    #     #        #        #         # # # ", " #    #    #   ######  ###     #     ###         # # # #"}
        Console.Write("Tell a string:")
        Dim Entry As String = Console.ReadLine()
        Dim j As Byte = 1
        Dim Letra As Char
        Dim CodigoAscii As Integer() = New Integer(Entry.Length - 1) {}

        For i As Integer = 0 To Entry.Length - 1
            Letra = Convert.ToChar(Entry.Substring(i, j))
            CodigoAscii(i) = Convert.ToInt32(Letra)
        Next

        Dim AnchoLetras As Integer = 7, AltoLetra As Integer = 7
        Dim numeroAscii As Integer = 32
        Dim countLineas As Integer = 0, countLetras As Integer = 0, countPosiciones As Integer = 0
        Dim LetraEncontrada As Boolean = False
        Dim cadena As String() = New String(AltoLetra - 1) {}

        For i As Integer = 0 To CodigoAscii.Length - 1

            For row As Integer = 0 To esqueleto.Length - 1

                If countLetras = 8 Then
                    row += AltoLetra - 1
                    countLetras = 0
                    countPosiciones = 0
                End If

                While (Not LetraEncontrada) AndAlso (countLetras < 8)

                    If CodigoAscii(i) = numeroAscii Then
                        LetraEncontrada = True
                    Else
                        numeroAscii += 1
                        countPosiciones += AnchoLetras
                        countLetras += 1
                    End If
                End While

                If (LetraEncontrada) AndAlso (countLineas < 7) Then

                    If i > 0 Then
                        cadena(countLineas) = cadena(countLineas) & esqueleto(row).Substring(countPosiciones, AnchoLetras)
                    Else
                        cadena(countLineas) = esqueleto(row).Substring(countPosiciones, AnchoLetras)
                    End If

                    countLineas += 1
                End If
            Next

            countLineas = 0
            numeroAscii = 32
            LetraEncontrada = False
            countPosiciones = 0
            countLetras = 0
        Next

        For i As Integer = 0 To cadena.Length - 1
            Console.WriteLine(cadena(i))
        Next
    End Sub
End Class

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