VB 在text1中输入多个单词,并统计出总共单词数,找出长度最长的单词并显示倒texe1中
2个回答
展开全部
Option Explicit
Private Sub Command1_Click()
Dim s As String
Dim a
Dim i As Integer, max As Integer
If Text1.Text = "" Then MsgBox "请输入单词,以空格分割": Exit Sub
s = Trim(Text1.Text)
s = Replace(s, " ", " ")
a = Split(s, " ")
max = 0
For i = LBound(a) To UBound(a)
If Len(a(i)) > max Then max = Len(a(i))
Next
Text1.Text = ""
For i = LBound(a) To UBound(a)
If Len(a(i)) = max Then Text1.Text = Text1.Text & a(i) & " "
Next
End Sub
Private Sub Command1_Click()
Dim s As String
Dim a
Dim i As Integer, max As Integer
If Text1.Text = "" Then MsgBox "请输入单词,以空格分割": Exit Sub
s = Trim(Text1.Text)
s = Replace(s, " ", " ")
a = Split(s, " ")
max = 0
For i = LBound(a) To UBound(a)
If Len(a(i)) > max Then max = Len(a(i))
Next
Text1.Text = ""
For i = LBound(a) To UBound(a)
If Len(a(i)) = max Then Text1.Text = Text1.Text & a(i) & " "
Next
End Sub
展开全部
单词和单词的分割加入是空格!
Private Sub Command1_Click()
If Trim(Text1.Text) = "" Then Exit Sub
Dim i As Integer
Dim temp As String
Dim sum As Integer
Dim maxlenword As String
Dim ArrayWord
ArrayWord = Split(Text1, " ", -1, vbTextCompare)
sum = UBound(ArrayWord) + 1
maxlenword = ArrayWord(0)
For i = 0 To UBound(ArrayWord)
If Len(maxlenword) <= Len(ArrayWord(i)) Then
maxlenword = ArrayWord(i)
End If
Next
Text1 = maxlenword
End Sub
Private Sub Command1_Click()
If Trim(Text1.Text) = "" Then Exit Sub
Dim i As Integer
Dim temp As String
Dim sum As Integer
Dim maxlenword As String
Dim ArrayWord
ArrayWord = Split(Text1, " ", -1, vbTextCompare)
sum = UBound(ArrayWord) + 1
maxlenword = ArrayWord(0)
For i = 0 To UBound(ArrayWord)
If Len(maxlenword) <= Len(ArrayWord(i)) Then
maxlenword = ArrayWord(i)
End If
Next
Text1 = maxlenword
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询