2014-01-20 203 views
0

好吧,所以我有问题添加到我的二维数组元素。我正在使用3个文本框来允许用户将项目输入到我的数组中。我的问题是我似乎无法让阵列过去(0,2)。我希望用户能够在每次点击添加按钮时添加一行输入。这是迄今为止我在我的代码中所拥有的。谁能帮忙?这不是我自己学习的课程。二维阵列VB

Option Strict On 
Option Explicit On 
Option Infer Off 

Public Class Form1 

Private strExams(49, 2) As String 

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click 

    Dim strStudent As String = txtStudent.Text 
    Dim strTest As String = txtTest.Text 
    Dim strScore As String = txtScore.Text 
    Dim count As Integer = 0 

    If count <= 49 Then 
     strExams(count, 0) = strStudent 
     strExams(count, 1) = strTest 
     strExams(count, 2) = strScore 
     count += 1 
    End If 

    txtStudent.Text = String.Empty 
    txtTest.Text = String.Empty 
    txtScore.Text = String.Empty 

    txtStudent.Focus() 

End Sub 

回答

1

尝试......你计数变量必须放在btnAdd_Click子外,否则将永远回重置为0,因此,你不会得到过去的(0,2)。

Option Strict On 
Option Explicit On 
Option Infer Off 

Public Class Form1 

Private strExams(49, 2) As String 
Dim count As Integer = 0 

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click 

Dim strStudent As String = txtStudent.Text 
Dim strTest As String = txtTest.Text 
Dim strScore As String = txtScore.Text 

If count <= 49 Then 
    strExams(count, 0) = strStudent 
    strExams(count, 1) = strTest 
    strExams(count, 2) = strScore 
    count += 1 
End If 

txtStudent.Text = String.Empty 
txtTest.Text = String.Empty 
txtScore.Text = String.Empty 

txtStudent.Focus() 

End Sub 
+0

非常感谢。我坐在这里试图弄清楚这个永远大声笑 – VinceCat

+0

高兴地帮助:) –