编写程序VB,在一个文本框中输入一个简单的英文句子,找出这个英文句子中最长的单词Private Sub Command1_Click()Dim word() As String,s As StringDim k As Integer,maxw As String,n As Integers = Text1.TextDon = InStr(s," ")If
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 13:13:18
编写程序VB,在一个文本框中输入一个简单的英文句子,找出这个英文句子中最长的单词Private Sub Command1_Click()Dim word() As String,s As StringDim k As Integer,maxw As String,n As Integers = Text1.TextDon = InStr(s," ")If
编写程序VB,在一个文本框中输入一个简单的英文句子,找出这个英文句子中最长的单词
Private Sub Command1_Click()
Dim word() As String,s As String
Dim k As Integer,maxw As String,n As Integer
s = Text1.Text
Do
n = InStr(s," ")
If n 0 Then
k = k + 1
ReDim Preserve word(k)
word(k) = Left(s,n - 1)
List1.AddItem word(k)
s = Right(s,n + 1)
End If
Loop Until n = 0
ReDim Preserve word(k + 1)
word(k + 1) = Left(s,Len(s) - 1)
List1.AddItem word(k + 1)
maxw = word(1)
For n = 2 To UBound(word)
If Len(word(n)) > Len(word(1)) Then
maxw = word(n)
End If
Next n
Text2 = maxw
End Sub
提示为溢出,k=k+1 变黄色
编写程序VB,在一个文本框中输入一个简单的英文句子,找出这个英文句子中最长的单词Private Sub Command1_Click()Dim word() As String,s As StringDim k As Integer,maxw As String,n As Integers = Text1.TextDon = InStr(s," ")If
Private Sub Command1_Click()
If Text1.Text = "" Then Exit Sub
Dim word As Variant,s As String
Dim k As Integer,maxw As String,n As Integer
s = Replace(Replace(Text1.Text,","," "),"."," ")
s = Replace(Replace(s,","," "),"."," ")
s = Replace(s,vbCrLf," ")
s = Trim(Replace(s," "," "))
If s = "" Then Exit Sub
word = Split(s," ")
n = UBound(word)
For k = 0 To n
If n = k Then Exit For
If Len(CStr(word(k + 1))) > Len(maxw) Then
maxw = word(k + 1)
End If
Next
MsgBox maxw & "=" & Len(maxw) & "字节"
End Sub