2013-06-23 124 views
0

下面檢索數據是我的代碼將數據輸入到一個數組和檢索信息vb.net輸入和從陣列

進入數據似乎也沒有問題,但是當我點擊按鈕來檢索信息,則只是在文本框中顯示0。

Public Class Form1 

    Dim Array(20) As String 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

    End Sub 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

     Dim counter As Integer 

     For counter = 0 To ListBox1.Items.Count - 1 
      Array(counter) = txtEnterMarks.Text(counter) 
     Next 

     Label1.Text = "omfg" 
    End Sub 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 

     For counter = 0 To Array.Length - 1 
      ListBox1.Items.Add(Array(counter)) 
     Next 
    End Sub 
End Class 
+2

然而,從今天http://stackoverflow.com/q/17256671/62576的另一個副本。你們所有的學校都參加了本週的家庭作業嗎?在發佈新問題之前,請至少進行一次基本搜索。謝謝。 –

+0

我搜索了每個地方,找不到解決方案 – user1427806

+0

我提供了一個鏈接,指向至少有一個地方,當您「搜索每個地方」時,您並未搜索到。今天至少還有[另一個帖子](http://stackoverflow.com/q/17256889/62576)提出了同樣的問題(它被封閉爲與我鏈接的副本相同)。你沒有很努力地搜尋;你需要更加努力。 :-) –

回答

0

再次..嘗試這種不同的答案

Structure Student  
    Dim Name As String 
    Dim Mark As Integer 
End Structure 

要保存您的輸入它:

Dim StudentsInfo as New List(Of Student) 
Dim si As New Student 

si.Name = txtEnterName.Text 
si.mark = val(txtEnterMark.Text) 
StudentsInfo.Add(si) 

從StudentsInfo獲得價值

txtEnterName.Text = StudentsInfo(0).Name 
txtEnterMark.Text = StudentsInfo(0).mark.ToString 

關於維護它到ListView ..再試試Goog先生樂...