'本程序从磁盘上读出文本文件,
'从中找出最长的单词
'单词间以空格或回车换行分隔
'每次从文件中读入一行内容存入变量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
'从中找出最长的单词
'单词间以空格或回车换行分隔
'每次从文件中读入一行内容存入变量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
解决方案 »
- 我在1996年用QB编写了一个中型DOS软件mmsi.exe,现在有那种软件可以将其逆向工程,还原出设计框架。
- [结论]如何对CMD窗口进行输入输出重定向
- 关于ToolBar的问题~~~~~头都疼了!~
- 高分紧急求助!VB的什么控件能实现图片、文本的任意摆放,要做成象杂志的样子!
- 如何实现自动根据文字长度调整FlexGrid的列宽?
- 打包出现的问题?
- 发现自己是2个小三角,散分,同时感谢所有热心帮助过我的网友,希望大家愉快!!
- MSDN可以只安装帮助文件吗?
- 如何获取窗口上的文字?
- enmity(灵感之源),来取分!bmp --> jpg
- 求购一个小程序,都来看看吧!
- 如何使用vb实现0.1毫秒间隔的事件触发
第二处: ……喔,这一行:Do While str1 > ""
引号间是不是少了一个空格?
2. Line Input #1, strl
3. strl=""
4. MaxLen
5. MaxWord=wordstr
完成