使用Robot从txt文件中读取不同行的内容并显示(续)
2006-11-25 21:29
831 查看
上一篇文章中介绍了如何使用Robot编写函数,取得txt文件中每一行的内容,但给出的脚本中还存在几个问题:1.函数没有提取出来,共用性不强 2.如果想从一个有n多行的文件中把所有内容取出,则每调用一次函数,函数内部都会跑一遍循环取值,很浪费
于是我又重新整理了一下,将函数放置到库文件(.sbl)中,并在里面定一一个全局变量cell(),取值函数ReturnCell变为子程序,删除返回值的参数,这个子程序中将取得的变量放到数组cell中,这样引用这个sbl的脚本就可以使用cell()的值了。脚本如下:
主脚本:txt
'$include: "FunctionLib.sbl"
Sub main '主脚本
Dim x as integer
Dim Location as string
Dim msgtext as string
Location = "D:/gvb.txt" '指定一个文件
x = returnrownum(location) '调用ReturnRowNum函数,返回这个文件中的行数
call ReturnCell(location,x) '调用ReturnCell,返回指定文件,指定行的内容
msgbox cell(0)
msgbox cell(3)
End sub
==============================================
FunctionLib.sbl
Global cell() '全局变量,动态数组
Function ReturnRowNum(Dircetory as string) as integer '返回指定文件的行数
Dim testscore as String
Dim x,i,y as integer
if IsMissing(Dircetory) then
msgbox "no Dircetory"
End if
Open Dircetory for Input as #1
x=0
i=0
Do Until x=Lof(1)
Line Input #1, testscore
x=x+1
i=i+1
y=Seek(1)
If y>Lof(1) then
x=Lof(1)
Else
Seek 1,y
End If
Loop
Close #1
ReturnRowNum = i
End Function
Sub ReturnCell(Dircetory as string,RowNum as integer) '子程序
Dim testscore as String
Dim x,i,y as integer
if IsMissing(Dircetory) then
msgbox "no Dircetory"
End if
if IsMissing(RowNum) then
RowNum = 0
End if
Redim cell(RowNum-1)
Open Dircetory for Input as #1
x=0
Do Until x=Lof(1)
Line Input #1, testscore
cell(x) = testscore
x=x+1
y=Seek(1)
If y>Lof(1) then
x=Lof(1)
Else
Seek 1,y
End If
Loop
Close #1
End Sub
于是我又重新整理了一下,将函数放置到库文件(.sbl)中,并在里面定一一个全局变量cell(),取值函数ReturnCell变为子程序,删除返回值的参数,这个子程序中将取得的变量放到数组cell中,这样引用这个sbl的脚本就可以使用cell()的值了。脚本如下:
主脚本:txt
'$include: "FunctionLib.sbl"
Sub main '主脚本
Dim x as integer
Dim Location as string
Dim msgtext as string
Location = "D:/gvb.txt" '指定一个文件
x = returnrownum(location) '调用ReturnRowNum函数,返回这个文件中的行数
call ReturnCell(location,x) '调用ReturnCell,返回指定文件,指定行的内容
msgbox cell(0)
msgbox cell(3)
End sub
==============================================
FunctionLib.sbl
Global cell() '全局变量,动态数组
Function ReturnRowNum(Dircetory as string) as integer '返回指定文件的行数
Dim testscore as String
Dim x,i,y as integer
if IsMissing(Dircetory) then
msgbox "no Dircetory"
End if
Open Dircetory for Input as #1
x=0
i=0
Do Until x=Lof(1)
Line Input #1, testscore
x=x+1
i=i+1
y=Seek(1)
If y>Lof(1) then
x=Lof(1)
Else
Seek 1,y
End If
Loop
Close #1
ReturnRowNum = i
End Function
Sub ReturnCell(Dircetory as string,RowNum as integer) '子程序
Dim testscore as String
Dim x,i,y as integer
if IsMissing(Dircetory) then
msgbox "no Dircetory"
End if
if IsMissing(RowNum) then
RowNum = 0
End if
Redim cell(RowNum-1)
Open Dircetory for Input as #1
x=0
Do Until x=Lof(1)
Line Input #1, testscore
cell(x) = testscore
x=x+1
y=Seek(1)
If y>Lof(1) then
x=Lof(1)
Else
Seek 1,y
End If
Loop
Close #1
End Sub
相关文章推荐
- 使用Robot从txt文件中读取不同行的内容并显示
- 【ASP.NET 进阶】定时执行任务实现 (定时读取和修改txt文件数字内容,无刷新显示结果)
- 使用python读取txt文件的内容,并删除重复的行数方法
- ASP读取显示TXT文件内容
- C++ 使用ifstream和getline读取txt文件内容
- 使用java读取txt里边的文件内容并获取大小(M).txt
- 使用Python将TXT文本内容读取后生成指定XML格式的文件
- 使用 PHP 读取文本(TXT)文件 并分页显示
- ASP读取显示TXT文件内容
- 使用python读取txt文件的内容,并删除重复的行数
- 使用dos 写bat时,使用for循环读取文件中的内容无任何显示
- 用ASP读取显示TXT文件内容的代码
- ASP读取显示TXT文件内容
- 使用 PHP 读取文本(TXT)文件 并分页显示
- ASP读取显示TXT文件内容
- 使用FileInputStream类, 实现从磁盘读取本应用程序源代码文件,并将文件内容显示在屏幕上。
- 使用缓冲流读取试题文件,每次显示试题文件中的一道题目。读取到字符“*”时候暂停读取,等待用户从键盘输入答案。用户做完全部题目后,程序给出用户的得分。Test.txt如下:
- 使用Python将TXT文本内容读取后生成指定XML格式的文件
- jsp读取txt文件后,将txt文件内容分页显示
- java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。