当前位置: 高中信息技术 / 综合题
  • 1. (2020高二上·嘉兴期末) 编写VB程序,实现在文本中统计以某字母开头的单词总数,并依次输出查找到的每个单词。程序功能如下:文本框Text1中输入文本(单词间用空格、“,”、”.”分隔),文本框Text2中输入开头字母,单击“查找”按钮Commmand1后,标签Label1中显示符合条件的单词总数,列表框List1中依次输出每个单词,程序运行界面如图所示。

    1. (1) 要使程序运行时,窗体Form1标题栏自动显示“统计指定字母开头的单词”,可在(单选,填字母:A .Form Load) /B .Form _Click(/ C .Command1 Click() 事件过程中添加相关语句来实现。
    2. (2) 实现上述功能的VB程序如下,请在划线处填入合适代码。

      Private Sub Command1_ Click()

          Dim i As Integer, j As Integer, n As Integer, flag As Boolean

          Dim st As String, szm As String, ch As String, word As String, tmp As String

          st = Text1. Text

          szm = Text2. Text

          flag = True: n=0

          For i=1 To Len(st)

             

              If ch = szm And flag = True Then

                  n=n+1: word = ch

                  For j=i+1 To Len(st)

                      tmp = Mid(st, j, 1)

                      If tmp<>””And tmp <>”.”And tmp <>“,” Then

                         

                      Else

                          List1. AddItem Str(n) +“.”+ word

                          i=j

                          Exit For

                      End If

                  Next j

              ElseIf ch=“” Or ch=“,” Or ch= “.”Then

                 

              Else

                  flag = False

             End If

          Next i

          Label1.Caption=“字母”+ szm +“开头的单词总数:”+ str(n)

      End Sub

微信扫码预览、分享更方便