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我要改我追问的。。。谢谢哦,我看一下,就怕看别人代码测试了,没有看到问题,你是在什么情况下有的提示错?经过空测试,错误:应该在 s = Text1.Text 下面判断:if s="" then exit sub
编写程序VB,在一个文本框中输入一个简单的英文句子,找出这个英文句子中最长的单词
编写程序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 变黄色
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 变黄色
其他人气:866 ℃时间:2020-05-10 09:09:08
优质解答
我来回答
类似推荐
猜你喜欢
- 1一次小刚的爸爸买了一篮子梨回家,小刚想分给家里每一个人,如果每人分3个,就剩下3个梨,如果每人分4个,
- 2old man had nothing in his hand.(同义句)the old man —— —— in his hand
- 31万箱苹果平均每箱因水分蒸发减轻800克,标准差为50克 计算样本容量为100箱时,X平均值小于等于700克的概率
- 4将一个长方形绕它的一边所在直线旋转一周,得到的几何体是圆柱,现有一个长为5厘米,宽为6厘米的长方形,分别绕它的长、宽所在直线旋转一周,得到不同的圆柱体,它们的体积分别是多少?
- 5数学找规律的题,第一个图正方形,4跟小棍,第二图4个小正方形12根,第n个图形需要几个小根
- 6英语翻译
- 7有一根烧红的铁钉,温度是800℃,质量是1.5g,温度降低到20℃,放出多少热量?
- 8八年级上册十二课中国石拱桥课后第二题四道小题的说明方法【 】说明了【 】事物的【 】特点
- 9两种方法计算a的m次方乘a的n次方乘a的p次方.
- 10Tom_____(not be)often late for school.