51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2932|回复: 2
打印 上一主题 下一主题

[Robot] 关于文件操作的一段代码,请高手帮忙解析

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2004-9-23 13:22:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
This example creates a file, puts the numbers 1-10 in it, then attempts to {Get} past the end of the file. The {On Error} statement traps the error and execution goes to the Debugger code which uses {Reset} to close the file before exiting.

Sub main
' Put the numbers 1-10 into a file
    Dim x as Integer
    Dim y as Integer
    On Error Goto Debugger
    Open "C:\TEMP001" as #1 Len=2
    For x=1 to 10
        Put #1,x, x
    Next x
    Close #1
    msgtext="The contents of the file is:" & Chr(10)
    Open "C:\TEMP001" as #1 Len=2
    For x=1 to 10
        Get #1,x, y
        msgtext=msgtext & Chr(10) & y
    Next x
    MsgBox msgtext
done:
    Close #1
    Kill "C:\TEMP001"
    Exit Sub
Debugger:
    MsgBox "Error " & Err & " occurred. Closing open file."
    Reset
    Resume done
End Sub

上面这段代码我总是运行不到Debugger标签这里,因为Get语句没有超出文件的最后啊,可是最上面的那段英文(书上copy来的)却说这个例子会企图超出文件的最后而出错,跳转到Debugger标签啊。怎么回事呢?

另外,Reset的到底实现了什么功能呢?

烦请哪位解答,谢谢了!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏

该用户从未签到

2#
发表于 2004-9-24 20:36:32 | 只看该作者
On Error Goto Debugger
的功能说当代码出现问题,或者出现异常,代码忽略错误运行到错误代码标签debugger

你的功能代码没有出现问题或者异常,所以没有执行到哪里!比如你创建文件的时候出现异常,那么代码就会执行到debugger的地方

reset的功能是关闭所有操作的文件!
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2004-9-28 10:37:55 | 只看该作者
那么既然用了Reset,跳转到Done标签后为什么还要用Close语句再关闭呢?
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /2 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-6-15 12:51 , Processed in 0.072847 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表