窗体上有1个名称为Command1的命令按钮;1个名称为List1、没有列表项的列表框。编写如下程序: Private Sub Command1_Click() Dim x As String, s As String, temp As String

admin2020-02-27  18

问题 窗体上有1个名称为Command1的命令按钮;1个名称为List1、没有列表项的列表框。编写如下程序:
Private Sub Command1_Click()
   Dim x As String, s As String, temp As String
   Dim i As Integer
   x = InputBox("输入字符串", "输入")
   If x <> "" Then
      For i = Len(x) To 1 Step -1
         s = Mid(x, i, 1)
         If s <> " " Then
            temp = s + temp
         Else
            List1.AddItem temp
            s = ""
            temp = ""
         End If
      Next
      List1.AddItem temp
   Else
      MsgBox "输入内容为空!"
   End If
End Sub
程序运行后,单击命令按钮Command1,并输入"Happy new year",则在List1中显示的内容为

选项 A、year
new
Happy
B、  Happy
new
year
C、raey
wen
yppaH
D、yppaH
wen
raey

答案A

解析 List1.AddItem可以为列表框添加列表项。For循环中通过Mid函数从字串中倒序取出字符,碰到空格时添加新列表项。选A)。
转载请注明原文地址:https://kaotiyun.com/show/1UTp777K
0

最新回复(0)