对于使用数组时循环不正确输出

时间:2017-03-11 19:52:08

标签: vb.net

我希望这段代码在运行时输出数组的第一行,暂停,然后输出数组中的第二行,每行输出的每个字符之间有一个延迟,但由于某种原因,它不是't'为我工作。

        Dim IntroText(4) As String
    IntroText(0) = "Konrad Czajkowski..."
    IntroText(1) = "...Presents"
    IntroText(2) = "...A text based game..."
    IntroText(3) = "...The Legend of Konrad and The Quest for Skairum"

    Dim IntroTextLength As Integer = Nothing
    IntroTextLength = IntroText(IntroText.Length - 1)

    For IntroCounter1 = 0 To IntroTextLength
        For IntroCounter2 = 0 To IntroText(IntroCounter1).Length - 1
            Console.Write(IntroText(IntroTextLength)(IntroCounter2))
            Threading.Thread.Sleep(50)
        Next
        Threading.Thread.Sleep(5000)
        Console.Clear()
    Next
    Console.Clear()

P.s我在VB.NET中使用控制台应用程序

1 个答案:

答案 0 :(得分:1)

试试这个。

Dim IntroText(4) As String
IntroText(0) = "Konrad Czajkowski..."
IntroText(1) = "...Presents"
IntroText(2) = "...A text based game..."
IntroText(3) = "...The Legend of Konrad and The Quest for Skairum"

Dim IntroTextLength As Integer = Nothing
IntroTextLength = IntroText.Length - 1

For IntroCounter1 = 0 To IntroTextLength - 1
    For IntroCounter2 = 0 To IntroText(IntroCounter1).Length - 1
        Console.Write(IntroText(IntroCounter1)(IntroCounter2))
        'Console.Write(IntroTextLength)
        Threading.Thread.Sleep(50)
    Next
    Threading.Thread.Sleep(500)
    Console.Clear()
Next
Console.Clear()