我在 VBA 中遇到以下问题
Dim backupFile As Integer
Dim backupFName As String
backupFName = xBackupDirName & "\" & "swap_backup_cf_" & xSwapID & ".txt"
backupFile = fopenForReading(backupFName)
Dim tmp As String
tmp = getLine(backupFile)
Dim b As Boolean
b = EOF(backupFile)
fopenforReading
andgetLine
正是您所期望的(我刚来自 C++ 背景,这些名字会更快地浮现在脑海中)。问题是最后一行给了我“错误的文件名或编号”错误。但是,tmp=getLine(backupFile)
读取backupFile
成功。我究竟做错了什么?
PS 只是为了完整性:
Public Function fopenForReading(xFname As String) As Integer
Dim iFile As Integer
iFile = FreeFile
Open xFname For Input As #iFile
fopenForReading = iFile
End Function
Public Function getLine(iFile As Integer) As String
Dim line As String
Line Input #iFile, line
getLine = line
End Function