vb6 调用TXT的问题

Dim b As String
Open App.Path & "\程序文件.txt" For Input As #1
Line Input #1, b
Label1.Caption = b '第一累计
Line Input #1, b
Label2.Caption = b
Line Input #1, b
Label3.Caption = b '第二累计
Line Input #1, b
Label4.Caption = b
Close #1
上面的代码是调用txt里的第1至4行,为label 1至4的caption,可如果txt里没有第4行的话,就会出现错误,怎样实现:txt里没有第4行,会出现提示“文件里没有名字”的msg

在前面加上on error resume next追问

在哪加啊,我是个笨蛋

追答

on error resume next
Dim b As String
Open App.Path & "\程序文件.txt" For Input As #1
Line Input #1, b
Label1.Caption = b '第一累计
Line Input #1, b
Label2.Caption = b
Line Input #1, b
Label3.Caption = b '第二累计
Line Input #1, b
Label4.Caption = b
Close #1

温馨提示:答案为网友推荐,仅供参考