[求助]编写程序:求一个字符串中最长的单词
刚开始学习VB,现在遇到这样一个题目不知道应该怎么做,请各位高手指点,谢谢!编写程序:求一个字符串中最长的单词(假设字符串中只包含字母和空格).
说明:
1、空格用来分隔不同单词
2、命令按钮“command1”用来实现查询功能;命令按钮“command2”用来实现清空功能
[CODE]Option Explicit
Private Sub Command1_Click()
Dim StrWord As String
Dim Words() As String
StrWord = InputBox("Please Input a Word")
Words = Split(StrWord, " ")
Dim i As Integer
Dim MaxLength As Integer
Dim MaxLengthWord As String
MaxLength = LBound(Words)
MaxLengthWord = Words(MaxLength)
For i = LBound(Words) + 1 To UBound(Words)
If (Len(Words(i)) > MaxLength) Then
MaxLength = Len(Words(i))
MaxLengthWord = Words(i)
End If
Next
Print MaxLengthWord
End Sub[/CODE]