这里是 VB 菜鸟,正在处理旧版 VB 6.0 应用程序。
当我在下面的函数中检查 lineno 的值时,我得到了预期值:
Public Function GetNumOfLines(filename As String) As Integer
Dim lineno as Integer
lineno = 0
Open App.Path + filename For Input As #1
Do While Not EOF(1)
lineno = lineno + 1
Line Input #1, linevar
Loop
Close #1
MsgBox "numOfLines: " & lineno 'This works
End Function
但是当我从 GetATRNames(如下)调用 GetNumOfLines 时,numOfLines 为 0:
Public Function GetATRNames() As String()
Dim filename as String
filename = "\atrname.dat"
Dim numOfLines as Integer
numOfLines = GetNumOfLines(filename)
MsgBox "numOfLines: " & numOfLines 'This does not
End Function
关于为什么 numOfLines = GetNumOfLines(filename) 给我的值与我在 GetNumOfLines 中检查时不同的任何想法?