Public Class 例5_7

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a(4, 4) As Integer
        Dim i, j, t As Integer
        Dim s1 As Integer, s2 As Integer
        Dim strtemp As String = ""
        t = 10                                          '第一个元素为10
        For i = 0 To 4
            For j = 0 To 4
                a(i, j) = t                         '对数组按行进行赋值
                t = t + 1
                strtemp = strtemp & a(i, j)         '控制输出格式
                If j = 4 Then
                    strtemp = strtemp & vbCrLf      'vbCrLf换行符
                Else
                    strtemp = strtemp & vbTab       'vbTab制表符
                End If
                If i = j Then s1 = s1 + a(i, j) '计算主对角线上元素之和
                If i + j = 4 Then s2 = s2 + a(i, j) '计算次对角线上元素之和
            Next j
        Next i
        TextBox1.Text = strtemp
        TextBox2.Text = s1
        TextBox3.Text = s2

    End Sub
End Class