编写VB程序,实现如下功能:在文本框Text1中输入整数n(1≤n≤10),单击“生成矩阵”按钮Command1,生成n2个10到99之间(包含10和99)的随机整数,并以n行、n列矩阵的形式显示在列表框List1中,再单击“对角线”按钮Command2,则在标签Label1中输出该矩阵对角线(左上角到右下角)上的数值,运行界面如图所示,程序代码如下。
(1)
要使文本框Text1上显示的默认文本由“8”改为“10”,可在其属性窗口中将属性的属性值改为“10”。
(2)
为了实现上述功能,请在划线处填入合适的代码。 Const MAXNUM = 100Dim i As Integer, n As IntegerDim a(1 To MAXNUM ^ 2) As IntegerPrivate Sub Command1_Click() Dim line As String n = Val(Text1.Text) line = ""List1.Clear Randomize For i = 1 To n ^ 2 a(i) = ① If i > 1 And i Mod n = 1 Then List1.AddItem line line = Str(a(i)) Else line = ② End If Next i List1.AddItem lineEnd SubPrivate Sub Command2_Click() Label1.Caption = ""For i = 1 to ③ Label1.Caption = Label1.Caption & Str(a(i + (i - 1) * n)) Next iEnd Sub① ② ③
答案: 【1】Text
【1】Int(Rnd() * 90 + 10)【2】line & Str(a(i))【3】n