在VB.Net中测试跟踪表

时间:2011-12-29 18:05:43

标签: vb.net

通过跟踪表并想检查我的结果是否正确,我设计了以下代码来检查循环的每个阶段,但是当我尝试运行时,代码不断抛出关于强制转换的错误。我可以看到错误回来的时候,写信线正在保存信息,但我做错了什么。

Module Module1


    Sub Main()
        Dim aWord As String
        Dim bWord As String
        Dim result As Boolean
        Dim temp As Char
        Dim pos As Integer
        Dim index As Integer
        index = 0
        aWord = "Simple"
        bWord = "abcdef"
        result = True
        If Not (aWord.Length = bWord.Length) Then
            result = False
        Else
            While index < bWord.Length And result
                temp = bWord.Chars(index)
                pos = aWord.IndexOf(temp)
                If pos >= 0 Then
                    aWord = aWord.Remove(pos, 1)

                Else
                    result = False
                End If

                WriteLine(bWord, aWord, temp, pos.ToString, index.ToString)

            End While

        End If

    End Sub


End Module

1 个答案:

答案 0 :(得分:1)

您正在错误地调用WriteLine()。它应该是:

WriteLine("{0}, {1}, {2}, {3}, {4}", bWord, aWord, temp, pos.ToString, index.ToString)