问题 问答题

[说明]
在一些应用场合中,需要对用户的输入数据进行检查监控。以下VisualBasic程序实现了对新添加到 List列表的内容进行监控,拒绝向List列表添加重复信息。例如,在List列表中存在元素“a01001;a01002”,如果用户输入数据为“aOl001”或“a01002”,系统则弹出提示信息,拒绝将新数据加入List列表;如果用户输入的数据不同与List列表中的任何一个元素,则作为新元素加入List中。VisualBasic界面显示如图11-5所示。根据程序功能说明,完成程序代码。


[代码1]
Begin VB.Form Form1
Caption=“List列表拒绝添加重复信息”
//...窗体描述(略)
Begin VB.CommandButton Command2
Caption=“退出”
//...窗体描述(略)
End
Begin VB.CommandButton ommand1
Caption=“添加”
//...窗体描述(略)
End
Begin VB.TextBox Text1
//...窗体描述(略)
End
Begin VB.ListBox List1
Height=1860
ItemData="Form1.frx": 0000
Left=1020
List="Form1.frx": 0002
TabIndex=0
Top=525
Width=2580
End
Begin VB.Label Labell
BackStyle=0’Transparent
Caption="请输入编号"
//...窗体描述(略)
End
End
[代码2]
Attribute VB_Name="Form1"
Attribute VB_GlobalNameSpace=False
Attribute VB_Creatable=False
Attribute VB_PredeclaredId=True
Attribute VB_Exposed=False
Private Sub Form_Load ( )
Listl.AddItem"a01001"
Listl.AddItem"a01002"
End Sub
Private Sub Command1 Click ( )
Dim Myval As Long
For i=0 To (1)
(2)
If (3) Then
MsgBox"系统不允许重复输入,请重新输入"
Exit Sub
End If
(4)
(5)
End Sub

答案

参考答案:(1)Listl.ListCount-1
(2)Listl.LisfIndex=i
(3)Listl.Text=Text1.Text Then
(4)Next i
(5)Listl.Addltem Text1.Text

解析: 本代码实现了对用户的输入数据进行检查监控。以下题目中的VisualBashc程序实现了对新添加到List列表的内容进行监控,拒绝向List列表添加重复信息。(1)为所有的列表个数;(2)、(3)实现了List列表的内容进行监控,避免重复;(4)实现循环控制变量i更新;(5)List列表的内容进行监控时数据合格,没有重复、接受。

解答题
单项选择题 A1型题