2013-03-08 94 views
0

我是新來的Visual Studio.I試圖寫在Visual Basic中的一個簡單的程序,從一個文本框中取一個13位數字,並將其數字寫入一個數組。然後它寫入數組的第二個成員(數字的第二個數字)到另一個文本框,但它不起作用。這裏是代碼:Visual Basic(錯誤代碼)

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

忘了VB,但不是它:'code = code/10'和'index = index-1'。我也不會使用「數組」作爲名稱。 – 2013-03-08 08:34:25

+1

Option Strict Off,這是最大的錯誤。 – Steve 2013-03-08 11:25:18

回答

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 
+0

感謝您的幫助。我曾經使用C++編寫程序,但不知道在Visual Basic中,我可以很容易地將char中的數字轉換爲整數。 – 2013-03-08 17:43:15

+0

不客氣Murad。 – dee 2013-03-08 19:04:06