VB中使用Open App.Path & "\caidan.txt" For Input As #fileno该代码导入文件 5
VB中使用OpenApp.Path&"\caidan.txt"ForInputAs#fileno该代码导入文件,文件名没错,文件也在,可运行程序是就是显示文件未找到,Pr...
VB中使用Open App.Path & "\caidan.txt" For Input As #fileno该代码导入文件,文件名没错,文件也在,可运行程序是就是显示文件未找到,
Private Sub Form_Activate()
Dim bianhao() As String, name1() As String, danjia() As Single
fileno = FreeFile
Open App.Path & "\caidan.txt" For Input As #fileno
Do While Not EOF(fileno)
i = i + 1
ReDim Preserve bianhao(i) As String
ReDim Preserve name1(i) As String
ReDim Preserve danjia(i) As Single
Input #fileno, bianhao(i), name1(i), danjia(i)
Loop
Close #fileno
For j = 1 To i
Combo2.AddItem j
Next j
End Sub 展开
Private Sub Form_Activate()
Dim bianhao() As String, name1() As String, danjia() As Single
fileno = FreeFile
Open App.Path & "\caidan.txt" For Input As #fileno
Do While Not EOF(fileno)
i = i + 1
ReDim Preserve bianhao(i) As String
ReDim Preserve name1(i) As String
ReDim Preserve danjia(i) As Single
Input #fileno, bianhao(i), name1(i), danjia(i)
Loop
Close #fileno
For j = 1 To i
Combo2.AddItem j
Next j
End Sub 展开
1个回答
展开全部
如果VB提示文件未找到,那就表示文件确实未找到,如果VB连这一点都判断错,那么它绝不可能历经10多年到现在都还有很多人用!所以你不要主观认定“文件名没错,文件也在”,因为App.Path很可能不是你想象中的值哦!,你可以在Open语句的前面先把App.Path & "\caidan.txt"的值显示出来,看看它是不是文件的实际路径,比如:
MsgBox App.Path & "\caidan.txt"
或者
MsgBox Dir(App.Path & "\caidan.txt") '如果显示空白就表示文件不存在
MsgBox App.Path & "\caidan.txt"
或者
MsgBox Dir(App.Path & "\caidan.txt") '如果显示空白就表示文件不存在
追问
确实是空白,可我要导入的文件确实在,那到底出了什么问题呢,我应该怎么改呢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询