单选题
VB
题号 #2536763
窗体上有1个名称为List1的列表框,其中已经输入了若干个项目,如图所示;还有2个文本框,名称分别为Text1、Text2,1个名称为Command1的命令按钮,并有下列事件过程。

Private Sub Co mmand1_Click()
Di mstr As Stri ng ,s As Stri ng ,k As Integer
s =Text1
str =""
For k =List1.ListCount -1To 0Step -1
If InStr(List1.List(k),s)>0Then
str =str &List1.List(k)&""
End If
Next k
If str =""Then
Text2="没有匹配的项目" Els
e Text2=str
End If
End Sub
程序运行时,在Text1中输入"京",单击命令按钮,则在Text2中显示的内容是( )。
参考答案
C
答案解析
InStr 函数格式是:InStr([首字符位置,]字符串1,字符串2[,n]),即在"字符串1"中查找"字符串2"若找到,则返回"字符串2"的第一个字符在"字符串1"中的位置。而"字符串1"的第一个字符的位置为1,即指定一字符串在另一个字符串中最先出现的位置。题中利用For 循环将s 即Text1中文本在列表框中各项进行查找,若s 在某
列表项中则将该项放入Str 中,并在Text2中显示该列表项,若Str 为空则在Text2中显示"没有匹配的项目"。
列表项中则将该项放入Str 中,并在Text2中显示该列表项,若Str 为空则在Text2中显示"没有匹配的项目"。
你可能感兴趣的试题
A.KeyAscii 参数是所按键的ASCII 码
B.KeyAscii 参数的数据类型为字符串
C.KeyAscii 参数可以省略
D.KeyAscii 参数是所按键上标注的字符
A.ABCDEFG
B.AGBFCE
C.GFEDCBA
D.AGBFCED
A.Private Sub Form_DragDrop(Source As Control ,XAs Si ngle ,Y As Si ngle)
banana . Move Picture1 . Left +X,Picture1 . Top +Y
End Sub
banana . Move Picture1 . Left +X,Picture1 . Top +Y
End Sub
B.Private Sub banana_DragDrop(Source As Control ,XAs Si ngle ,Y As Si ngle)
Source . Move Picture1 . Left +X,Picture 1 . Top +Y
End Sub
Source . Move Picture1 . Left +X,Picture 1 . Top +Y
End Sub
C.Private Sub Picture1_DragDrop(Source As Control ,X As Si ngle ,Y As Si ngle)
Source . Move Picture1 . Left +X,Picture1 . Top +Y
End Sub
Source . Move Picture1 . Left +X,Picture1 . Top +Y
End Sub
D.Private Sub Picture1_DragDrop(Source As Control ,X As Si ngle ,Y As Si ngle)
banana . Move banana . Left +X,banana . Top +Y
End Sub
banana . Move banana . Left +X,banana . Top +Y
End Sub
