Function return value for Main Learn programming Visual Basic (VB.net)

Lesson:

Functions


Exercise:

Function return value for Main


Objetive:

Create a Visual Basic (VB.net) program in which you write a title (using the previous WriteTitle function) which the user will specify in command line. If no text is specified, your program will display an error message and return a value of 1 to the operatiing system.


Code:

Imports System
Public Class exercis121
    Public Shared Sub WriteTitle(ByVal text As String)
        Dim numOfSpaces As Integer = (80 - text.Length * 2) / 2
        text = text.ToUpper()

        For i As Integer = 0 To numOfSpaces - 1
            Console.Write(" ")
        Next

        For i As Integer = 0 To text.Length * 2 - 1 - 1
            Console.Write("-")
        Next

        Console.WriteLine()

        For i As Integer = 0 To numOfSpaces - 1
            Console.Write(" ")
        Next

        For i As Integer = 0 To text.Length - 1
            Console.Write(text(i) & " ")
        Next

        Console.WriteLine()

        For i As Integer = 0 To numOfSpaces - 1
            Console.Write(" ")
        Next

        For i As Integer = 0 To text.Length * 2 - 1 - 1
            Console.Write("-")
        Next

        Console.WriteLine()
    End Sub

    Public Shared Function Main(ByVal args As String()) As Integer
        If args.Length <> 1 Then
            Console.WriteLine("What??!!")
            Return 1
        End If

        WriteTitle(args(0))
        Return 0
    End Function
End Class

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