当前位置: 高中信息技术 / 综合题
  • 1. (2020·温州模拟) 小董编写了一个有关“筛选操作”的VB程序,实现如下功能:在文本框Text1中显示一组随机生成个位数为“9”的两位数(原始数据),在文本框Text2中输入筛选个数,单击“操作”按钮Command1后,在文本框Text3中按降序显示所筛选个数的不重复最大数据(以逗号分隔并以数据结尾),若在文本框Text2中输入的数大于原始数据中不相同数的个数,则在文本框Text3中显示“筛选的个数太大,请重新输入!”。程序运行界面如图所示。

    1. (1) 如图所示,该VB程序的窗体中共有类对象(填数字)。
    2. (2) 实现上述功能的VB程序如下,请在划线处填入合适的代码。

      Const n = 10

      Dim d(n) As Integer, c As Integer

      Private Sub Form_Load()

         Dim i As Integer, j As Integer, f As Boolean, s As String

          Randomize

          c = n

          For i = 1 To n

              f = False

               d(i) =       ①         ' 随机生成个位数为“9”的两位数

               For j = 1 To i - 1

                  If      ②       Then f = True

               Next j

               If f Then c = c - 1

          Next i

      '原始数据在文本框Text1中显示。代码略

      End Sub

      Private Sub Command1_Click()

      Dim i As Integer, j As Integer, k As Integer, m As Integer

      Dim cnt As Integer,t As String, s As String

      d(0) = 100

      cnt = Val(Text2.Text)

          If cnt > c Then

      Text3.Text = "输入筛选的个数太大,请重新输入!"

         Exit Sub      'Exit Sub表示退出过程

      End If

      For i = 1 To cnt

       k = i

      For j = i + 1 To n

      If d(j) < d(i - 1) And ( ) Then k = j

      Next j

            If k <> i Then

                  t = d(i): d(i) = d(k): d(k) = t

            End If

      Next i

      For i = 1 To cnt

            s = s + Str(d(i)) + ","

      Next i

      Text3.Text =      ③    

      End Sub

       ② ③ 

    3. (3) 程序中加框处代码有错,请改正。

微信扫码预览、分享更方便