需要帮助输出控制台应用程序

时间:2014-11-26 05:22:47

标签: vb.net

下面是我学院的一个控制台应用程序项目,除了输出是脱节的以外,它工作得很完美,我想让它们像显示的桌子......我不知道如何制作输出就像一张桌子......

模块模块1

Dim college(4, 2)
Dim name As String
Dim Subject As String
Dim score As Decimal
Dim Record As Decimal
Dim Row As Decimal
Dim SortOut As Decimal
Dim TotRow As Decimal

Sub Main()

    Console.Write("Enter total number of student to process: ")
    Record = Console.ReadLine()

    SortOut = Record
    TotRow = Record - 1

    Row = TotRow

    Do While Row >= 0

        Console.Write("Enter Your Name: ")
        name = Console.ReadLine()


        Console.Write("Enter your subject : ")
        Subject = Console.ReadLine()


        Console.Write("Enter your score: ")
        score = Console.ReadLine()


        Call Input()

        Call RowStep()

    Loop


    Call Output()

    Console.ReadLine()

End Sub

Sub Input()

    college(Row, 0) = name
    college(Row, 1) = Subject
    college(Row, 2) = score

End Sub

Sub RowStep()

    Row = Row - 1

End Sub


Sub Output()

    Console.WriteLine()
    Console.WriteLine()

    Row = 0

    Do While Row < SortOut

        Console.WriteLine((college(Row, 0)))
        Console.WriteLine((college(Row, 1)))
        Console.WriteLine((college(Row, 2)))

        Row = Row + 1

    Loop

End Sub

结束模块

1 个答案:

答案 0 :(得分:0)

如果&#34;输出像表&#34;你的意思是在列中对齐,然后你可以String.Format输出你的所有内容。

Dim format as String = "{0,-25}{1,25}"

Console.WriteLine(String.Format(format, "Your name:", college(Row, 0)))
Console.WriteLine(String.Format(format, "Your subject:", college(Row, 1)))
Console.Writeline(String.Format(format, "Your score:", college(Row, 2)))

哪个应输出如下内容:

Your name:    Justin Ryan
Your subject:   Chemistry
Your score:            42

还有Console.WriteLine的重载,它提供了相同的功能。

Console.WriteLine(format, "Your name:", college(Row, 0))
Console.WriteLine(format, "Your subject:", college(Row, 1))
Console.Writeline(format, "Your score:", college(Row, 2))

回应提问者的评论:

Dim format As String = "{0,-25}{1,-25}{2}"

Console.WriteLine(format, "Name:","Subject:","Score:")
Do While Row < SortOut
    Console.WriteLine(format, college(Row, 0), college(Row, 1), college(Row, 2))
    Row = Row + 1
Loop