VB中使用open遇到的怪问题

来源:百度知道 编辑:UC知道 时间:2024/06/09 14:09:09
intFileNum = FreeFile()
Open GetAppPath + "tmpNoOral.dat" For Append As intFileNum

在一个程序中使用了这两句代码,遇到个怪问题,发现程序运行到open句后创建了这个文件,但是程序就此死机不动不往下执行了,请问这是什么原因,要怎么解决?

看起来没有问题啊。你单步调试看看?考虑2个问题
1、GetAppPath 是不是根目录,涉及到“\”问题
2、intFileNum 类型必须是int,且打开语句有个"#"号,比如
Open GetAppPath + "tmpNoOral.dat" For Append As #1
不是
Open GetAppPath + "tmpNoOral.dat" For Append As 1

刚才查了半天,好像没找到GetAppPath函数啊!

建议你这样改,经测试完全正常:
Private Sub Command1_Click()
intfilenum = FreeFile()
Open App.Path + "\tmpNoOral.dat" For Append As intfilenum
Write #intfilenum, 123
Close intfilenum
End Sub