单选题 VB
题号 #2273190

窗体上有1个名称为List1的列表框,其中已经输入了若干个项目,如图所示;还有2个文本框,名称分别为Text1、Text2,1个名称为Command1的命令按钮,并有下列事件过程。
Private Sub Command1_Click(  )
Dim str As String,S As String.k As Integer
s=Text1
str =""
For k=Listl.ListCount-1 To 0 Step-1
If InStr(List1.List(k),s)>0 Then
str=str & List1.List(k)&""
End If
Next k
If str=""Then
Text2="没有匹配的项目"
Else
Text2=str
End If
End Sub

程序运行时,在Text1中输入"京",单击命令按钮,则在Text2中显示的内容是(  )。

进入在线模考

参考答案

C

答案解析

C。【解析】InStr函数格式是:InStr([首字符位置,]字符串1,字符串2[,n]),即在“字符串1”中查找“字符串2”若找到,则返回“字符串2”的第一个字符在“字符串1”中的位置。而“字符串1”的第一个字符的位置为1,即指定一字符串在另一个字符串中最先出现的位置。题中利用For循环将S即Text1中文本在列表框中各项进行查找,若S在某列表项中则将该项放入Str中,并在Text2中显示该列表项,若Str为空则在Text2中显示“没有匹配的项目”。

你可能感兴趣的试题

A.KeyAscii参数是所按键的ASCII码
B.KeyAscii参数的数据类型为字符串
C.KeyAscli参数可以省略
D.KeyAscii参数是所按键上标注的字符
A.Private 3ub Form—DragDrop(Source As Control,X As Single,Y As Single)
banana.Move Picture1.Left+X,Picture1.Top+Y
End Sub
B.Private Sub banana_DragDrop(Source As Control,X As Single,Y As Single)
Source.Move Picture1.Left+X,Picture 1.Top+Y
End Sub
C.Private Sub Picture1_DragDrop(Source As Control,X As Single,Y As Single)
Source.Move Picture1.Left+X,Picture1.Top+Y
End Sub
D.Private Sub Picture1_DragDrop(Source As Control,X As Single,Y As Single)
banana.Move banana.Left+X,banana.Top +Y
End Sub
找试题 · 找答案 · 找资料 在线模考