Ejercicio
Función devuelve valor para Main
Objetivo
Cree un programa en Visual Basic en el que escriba un título (utilizando la función WriteTitle anterior) que el usuario especificará en la línea de comandos. Si no se especifica ningún texto, el programa mostrará un mensaje de error y devolverá un valor de 1 al sistema operativo.
Código
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