vb6函数不返回值
这里是VB noob,处理遗留的VB6.0应用程序 当我在下面的函数中检查lineno的值时,我得到的是预期值:vb6函数不返回值,vb6,Vb6,这里是VB noob,处理遗留的VB6.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 = li
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中检查时的值不同吗?你没有返回值。付诸表决:
GetNumOfLines = 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
'return number of lines
GetNumOfLines = lineno
End Function
您需要从GetNumOfLines函数返回值 添加行
GetNumOfLines = lineno
作为函数的最后一行