-2

生徒の名前とマークを入力するテキスト ボックスが 2 つあります。

Visual Basic で配列を作成する方法がわかりません

配列は多次元である必要があり、新しいマークと名前が入力されるたびに増加するインデックスも必要です。

配列が完成したら、結果をリスト ボックスに表示する必要があります。

ありがとうございました

編集!!!

これは私が今持っているコードですが、まだエラーはほとんどありません

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

    Dim LName As New List(Of String)
    Dim LMark As New List(Of Integer)


    LName.Add(txtEnterName.Text)
    LMark.Add(txtEnterMarks.Text)

    For counterOne As Integer = 0 To 10

        For counterTwo As Integer = 0 To 10

       Array[counterOne][counterTwo] = listview.text

        Next

    Next
End Sub
4

2 に答える 2

2

基本的にはこのように..

Dim LName as New List(Of String)
Dim LMark as New List(Of Integer)

したがって、テキストボックスを .. に追加する場合

LName.Add(Textbox1.Text)
LMark.Add(TextBox2.Text)

次のことについて学ぶ必要がありますList Of..Googleさんがきっとあなたを助けてくれるでしょう..

ViewListBoxリストボックスになるには.. 2列で使用する方が良い..

于 2013-06-23T00:56:01.297 に答える
0

この種のアプリケーションでは、配列はややこしいものです。取得した入力に応じてサイズを増減するのは簡単ではありません。リストの方がはるかに使いやすいです。データの 2 つの部分を結び付けるキー値ペアのリストを使用することもできます。

Public Class Form2
    'Declare the list here so that it's available to the whole class    
    Dim AllMarks As New List(Of KeyValuePair(Of String, Integer))
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
    Dim Mark As Integer
    If Integer.TryParse(txtEnterMarks.Text, Mark) AndAlso txtEnterName.Text <> "" Then
        AllMarks.Add(New KeyValuePair(Of String, Integer)(txtEnterName.Text, Mark))
    End If
    'Using the datasource property is a quick and easy way to fill your listbox
    ListBox1.DataSource = Nothing
    ListBox1.Items.Clear()
    ListBox1.DataSource = AllMarks
    txtEnterMarks.Text = ""
    txtEnterName.Text = ""
End Sub
End Class
于 2013-06-23T06:22:41.347 に答える