|
-
Apr 19th, 2003, 09:07 AM
#1
Thread Starter
Frenzied Member
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.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Apr 19th, 2003, 09:11 AM
#2
Frenzied Member
App.Path & "SuitData.qqq"
If that's what you use then change it to App.Path & "\SuitData.qqq"
-
Apr 19th, 2003, 10:05 AM
#3
Thread Starter
Frenzied Member
McGenius: The BackSlash (\) was supplied as part of App.Path.
My problem is not the syntax. I do not understand why the On Error does not seem to function as expected. I expected it to cause control Flow to go to FileError due to the attempt to Open & Get from a nonexistent file.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Apr 19th, 2003, 10:16 AM
#4
Frenzied Member
Hmm ...
First: App.Path does not supply last backslash unless you did
Second: what exactly are you expecting to fail ??? Error hanlder won't be triggered just because InputStamp.ProjectName <> FileStamp.ProjectName - it must be a real time error such "Invalid file name ..." or so to occur, otherwise it's an errorless flow.
-
Apr 19th, 2003, 11:49 AM
#5
Need-a-life Member
Originally posted by McGenius
Hmm ...
First: App.Path does not supply last backslash unless you did
Second: what exactly are you expecting to fail ??? Error hanlder won't be triggered just because InputStamp.ProjectName <> FileStamp.ProjectName - it must be a real time error such "Invalid file name ..." or so to occur, otherwise it's an errorless flow.
App.Path supplies the backslash if your app is loaded from the root of a drive.... and if it's loaded from a net folder ("\\computername\folder\")
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 19th, 2003, 11:53 AM
#6
-
Apr 19th, 2003, 11:55 AM
#7
Guv...
Code:
Open File_Name For Binary Access Read Lock Write As SuitFileNumber
When a file is opened as Binary, Random, Append, or Output, the file is created if it doesn't already exist. An Open will only fail if the file is opened for Input. Since it is now a zero byte file, the Get attempt will have zero bytes to read, hence the uninitialized data area.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 19th, 2003, 07:35 PM
#8
Frenzied Member
Originally posted by Mc Brain
App.Path supplies the backslash if your app is loaded from the root of a drive.... and if it's loaded from a net folder ("\\computername\folder\")
That isn't always true.
-
Apr 19th, 2003, 07:41 PM
#9
-
Apr 19th, 2003, 07:46 PM
#10
Frenzied Member
For some reason, Mc Brain you're always looking at immediate result HOWEVER if you read my previous post one more time you'll see 2 words: isn't always ... VB's App object is very problematic and is known for years as very unstable one.
-
Apr 19th, 2003, 09:48 PM
#11
Need-a-life Member
-
Apr 19th, 2003, 09:55 PM
#12
Frenzied Member
Originally posted by Mc Brain
... You have to code your app so that this slash won't "hurt" you.
Oh, that's outta question ...
-
Apr 20th, 2003, 10:42 AM
#13
Thread Starter
Frenzied Member
CrptcBlade:Thanx!! You were correct: Open Binary created an empty file. The Get could read no data, but did not fail since the file existed.
This forum has yet to fail me.
BTW: It seems strange that Open for input would create a file instead of complaining about it being nonexistent.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|