问题 填空题

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

【代码5-1】 Begin VB.Form Forml Caption= "List 列表拒绝添加重复信息"//...窗体描述(略) Begin VB.CommandButton Command2 Caption= "退出"//...窗体描述(略) End Begin VB.CommandButton Commandl Caption= "添加"//...窗体描述(略) End Begin VB.TextBox Text1 //...窗体描述(略) End Begin VB.ListBox List1 Height = 1860 ItemData= "Form1.fix": 0000 Left = 1020 List = "Form1.fix": 0002 TabIndex= 0 Top = 525 Width = 2580 End Begin VB.Labe1 Labe11 BackStyle= 0 ’Transparent Caption= "请输入编号" //...窗体描述(略) End End 【代码5-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 () List1.AddItem "a01001" List1.AddItem "a01002" End Sub Private Sub Cormnand1 Click () Dim Myval As Long For i=0 To (1) (2) If (3) Then MsgBox "系统不允许重复输入,请重新输入" Exit SubEnd If (4) (5) End Sub

答案

参考答案:为所有的列表个数;(2)、(3)实现了List列表的内容进行监控,避免重复;(4)为循环控制变量i更新;(5)Lis列表的内容进行监控时数据合格,没有重复,接受。

解析:(1)List1.ListCount-1 (2) List1.ListIndex = i (3) List1.Text = Text1.Text Then (4) Next i (5) List1.Addltem Text1.Text

单项选择题
问答题 简答题