vb.net从Array输入和检索数据

时间:2013-06-23 03:48:57

标签: 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

1 个答案:

答案 0 :(得分: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 ..再次尝试Google先生......