Visual Basic(代码中的错误)

时间:2013-03-08 08:25:30

标签: vb.net visual-studio-2012

我是Visual Studio的新手。我试图在Visual Basic中编写一个简单的程序,它从文本框中取一个13位数字并将其数字写入数组。然后它写入数组的第二个成员(数字的第二个数字)到另一个文本框,但它不起作用。这是代码:

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim array(12) As Integer
        Dim index As Integer = 11
        Dim code As Long = TextBox1.Text
        Do While index >= 0
            array(index) = code Mod 10
            code /= 10
            index -= 1
        Loop
        TextBox2.Text = array(1)
    End Sub
End Class

你能告诉我什么是错的吗?

1 个答案:

答案 0 :(得分:1)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim array(12) As Integer
    Dim index As Integer = 11
    Dim code As Char() = TextBox1.Text.ToCharArray()

    For i As Integer = 0 To code.Count - 1
        array(i) = Integer.Parse(code(i))
    Next

    TextBox2.Text = array(1)
End Sub