水浒神兽图文攻略:VB6.0导入文件,点取消时出现“路径/文件访问错误”

来源:百度文库 编辑:高考问答 时间:2024/04/19 01:05:40
Dim strFileName As String '文件名
Dim lngFileNo As Long '文件号
Dim strTemp As String

strFileName = "" & Text5.Text & ""

'得到空闲文件号
lngFileNo = FreeFile()
'打开文件
Open strFileName For Input As lngFileNo '提示错误行,请问有方法可以解决吗?

Do Until EOF(lngFileNo)
Line Input #lngFileNo, strTemp
List1.AddItem strTemp
Loop

'关闭文件
Close lngFileNo
不好意思,你回答错误了,正确的是
strFileName = "" & Text5.Text & ""
If strFileName = "" Then
Exit Sub
Else
.....

end if

Private Sub Form_Load()
Dim strFileName As String '文件名
Dim lngFileNo As Long '文件号
Dim strTemp As String

strFileName = "f:\Text5.txt"

'得到空闲文件号
lngFileNo = FreeFile()
'打开文件
Open strFileName For Input As lngFileNo

Do Until EOF(lngFileNo)
Line Input #lngFileNo, strTemp
List1.AddItem strTemp
Loop

'关闭文件
Close lngFileNo
End Sub
错是没错了 但是不知道能不能符合你的要求