设有如下通用过程:Public Function Fun (xStr As String) As String Dim tStr As String,strL As Integer tStr=-" " strL=Len(xStr)

admin2009-09-28  15

问题 设有如下通用过程:Public Function Fun (xStr As String) As String    Dim tStr As String,strL As Integer    tStr=-" "    strL=Len(xStr)    i=strL/2    Do Whilei<=strL        tStr=tStr &id(xStr,i+1,1)        i=i+1    Loop    Fun=tStr & tStrEnd Function    在窗体上画—个名称为Text1的文本框和—个名称为Command1的命令按钮,然后编写如下的事件过程:Private Sub Command1_ Click()    Dim S1 String    S1="ABCDEF"    Text1.Text=LCase(Fun(S1))End Sub    程序运行后,单击命令按钮,文本框中显示的是 ______。

选项 A、ABCDEF
B、abcdef
C、defdef
D、defabc

答案C

解析 Mid(字符串,p,n):从第p个字符开始,向后截取n个字符。p和n都是算术表达式。
“&”:字符串连接运算符,将两个字符串按顺序连接起来。
LCase(字符串):将字符串所有的字母都转换成小写字符。
Len(字符串):返回字符串的长度。
由LCase可知,最后结果为小写字符串,可排除选项A。当Fun过程用语句Fun(S1)调用后,S1的值“ABCDEF”被赋给xStr,执行第一次循环时Mid(xStr,i+1,1)相当  Mid(xStr,4,1),此时tStr=D,执行第二次循环时Mid(xStr,i+1,1)相当于Mid(xStr,5,1),此时tStr=DE,执行第三次循环时Mid(xStr,i+1,1)相当于Mid(xStr,6,1),此时tStr=DEF,执行第四次循环时Mid(xStr,i+1,1)相当于Mid(xStr,7,1),没有取到值,此时tStr=DEF,i的值为7,不满足循环条件,循环结束,Fun=tStr & tStr=DEFDEF,由此判断选项C正确。
转载请注明原文地址:https://kaotiyun.com/show/IS1p777K
0

随机试题
最新回复(0)