Error opening/reading file??
The following code attempted to open and read a nonexistent file, but did not act the way I thought it would. The intent is to generate the file if it does not already exist. I expected the On Error to direct Control Flow to FileError, but the bolded MsgBox Statement executed.
VB Code:
On Error GoTo FileError
SuitFileNumber = FreeFile
Open File_Name For Binary Access Read Lock Write As SuitFileNumber
Get SuitFileNumber, 1, InputStamp
If InputStamp.ProjectName = FileStamp.ProjectName _
And InputStamp.AuthorFirst = FileStamp.AuthorFirst _
And InputStamp.AuthorLast = FileStamp.AuthorLast _
And InputStamp.RecordCount = 512 Then
'Fall through and read file'
Else
[b]Junk = MsgBox("File corrupted or not Suit Data File")[/b]
Close SuitFileNumber
ThereIsSuitData = False
Exit Function
End If
[b]. . . [/b]
FileError:
[b]. . .[/b]
The above code is in a Function. I have included only the code which seems pertinent. File_Name is passed to the Function as parameter and seems to be syntactically correct.
App.Path & "SuitData.qqq" was used, and Debug analysis indicated that it became the name of a nonexistent file.
I expected the Open to fail, causing Control Flow to go to FileError. The input area looks like uninitialized data, indicating that no I/O actually occurred.
Why did neither the Open nor the Get cause control flow to go to FileError?
BTW: Due to the way some mainframes react, I always supply a place for values returned from Functions. Hence: Junk = MsgBox.