位置:首页 > 题库频道 > 其它分类 > 计算机其它 > 二级二级VB2010年9月全国计算机等级考试二级VB程序设计

下面函数的功能应该是:删除字符串str中所有与变量ch相同的字符,并返回删除后的结果。例如:若str=“ABCDABCD”,ch=“B”,则函数的返回值为:“ACDACD”Function delchar(str As String, ch As String) As StringDim k As Integer, temp As String, ret As Stringret = ""For k = 1 To Len(str)temp = Mid(str, k, 1)If temp = ch Thenret = ret & tempEnd IfNext kdelchar = retEnd Function但实际上函数有错误,需要修改。下面的修改方案中正确的是(    )。

发布时间:2024-07-09

A.把ret = ret & temp改为ret = temp

B.把If temp = ch Then改为If temp<> ch Then

C.把delchar = ret改为delchar = temp

D.把ret="" 改为temp=""

试卷相关题目

  • 1请阅读程序:Option Base 1Private Sub Form_Click()Dim arr(4, 4) As IntegerFor i = 1 To 4For j = 1 To 4arr(i, j) = (i - 1) * 2 + jNextNextFor i = 3 To 4For j = 3 To 4Print arr(j, i);Next jPrintNextEnd Sub程序运行后,单击窗体,则输出结果是(    )。

    A.5 76 8

    B.6 87 9

    C.7 98 10

    D.8 108 11

    开始考试点击查看答案
  • 2下列可以打开随机文件的语句是(    )。

    A.Open "file1.dat" For Input As #l

    B.Open "file1.dat" For Append As #l

    C.Open "file1.dat" For Output As #1

    D.Open "file1.dat" For Random As #1 Len=20

    开始考试点击查看答案
  • 3在窗体上画一个命令按钮(其名称为Commandl),然后编写如下代码:Private Sub Command1_Click()Dim aa = Array(1, 2, 3, 4)i = 3: j = 1Do While i >= 0s = s + a(i) * ji = i – 1 : j = j * 10LoopPrint sEnd Sub运行上面的程序,单击命令按钮,则输出结果是(    )。

    A.432l

    B.123

    C.234

    D.1234

    开始考试点击查看答案
  • 4请阅读程序:Private Sub Form_Click()m = 1For i = 4 To 1 Step -1Print str(m);m = m + 1For j = 1 To iPrint "*";Next jPrintNext iEnd Sub程序运行后,单击窗体,则输出结果是(    )。

    A.1****2***3**4*

    B.4****3***2*1*

    C.************

    D.**********

    开始考试点击查看答案
  • 5在窗体上画一个命令按钮,其名称为Command1,然后编写如下事件过程:Private Sub Command1_Click()Dim a$, b$, c$, k%a = "ABCD"b = "123456"c = ""k = 1Do While k <= Len(a) Or k <= Len(b)If k <= Len(a) Thenc = c &amp; Mid(a, k, 1)End IfIf k <= Len(b) Thenc = c &amp; Mid(b, k, 1)End Ifk = k + 1LoopPrint cEnd Sub运行程序,单击命令按钮,输出结果是(    )。

    A.123456ABCD

    B.ABCD123456

    C.D6C584A321

    D.A1B2C3D456

    开始考试点击查看答案
  • 6在窗体上画一个命令按钮和两个文本框,其名称分别为Commandl、Textl和Text2,在属性窗口中把窗体的KeyPreview属性设置为True,然后编写如下程序:Dim S1 As String, S2 As StringPrivate Sub Form_Load()Text1.Text = ""Text2.Text = ""Text1.Enabled = FalseText2.Enabled = FalseEnd SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)S2 = S2 &amp; Chr(KeyCode)Print S2End SubPrivate Sub Form_KeyPress(KeyAscii As Integer)S1 = S1 &amp; Chr(KeyAscii)Print S1End SubPrivate Sub Command1_Click()Text1.Text = S1Text2.Text = S2S1 = ""S2 = ""End Sub程序运行后,先后按“a”、“b”、“c”键,然后单击命令按钮,在文本框Textl和Text2中显示的内容分别为(    )。

    A.abe和ABC

    B.空白

    C.ABC和abc

    D.出错

    开始考试点击查看答案
返回顶部