'本程序从磁盘上读出文本文件,
'从中找出最长的单词
'单词间以空格或回车换行分隔
'每次从文件中读入一行内容存入变量st1
'查找完成后,在text1内显示单词的长度,
'text2显示最长的单词这是题目。程序如下:Private Sub Command1_Click()
  Dim str1 As String, MaxWord As String, wordstr As String
  Dim Maxlen As Integer, wordlen As Integer, mp As Integer
  Maxlen = 0: wordlen = 0
  MaxWord = "": wordstr = ""
  CommonDialog1.Filter = "*.txt|*.txt;*.doc"
  CommonDialog1.Action = 1
  ————————————————————————————
  
  Do While Not EOF(1)
  ————————————
  
     Do While str1 > ""
        mp = InStr(str1, "")
        
           If mp = 0 Then
              wordstr = str1
              ————————————
           Else
              wordstr = Left(str1, mp - 1)
              str1 = Trim(Mid(str1, mp + 1))
           End If
           
           wordlen = Len(wordstr)
          If wordlen > —— Then
              Maxlen = wordlen
              ——————————
          End If
          
     Loop
  Loop
     Text1 = Maxlen
     Text2 = MaxWord
     Close #1
End Sub