[Windows Programming] File Exception Handling not Works

Just starting out? Need help? Post your questions and find answers here.
User avatar
JamieVanCadsand
User
User
Posts: 34
Joined: Sun Jun 24, 2018 12:28 pm
Location: Holland

[Windows Programming] File Exception Handling not Works

Post by JamieVanCadsand »

Hey Windows Programmers....

I try to create an file importer, called an test to figure out how i can create an file exception handler,
just if the file is not found, then give an error... but it don't works...

So this is my script, written in PB5.6.2, on windows XP:

Code: Select all

;Make File Error
Procedure GetFileError()
  MessageRequester("Fatal Error!", "Cant find File", #PB_MessageRequester_Error)
EndProcedure


;Try to find File
File$ = OpenFileRequester("Import", "doc.txt", "Text (*.txt) | *.txt", 0)
If File$ 
  MessageRequester("File Info", File$, #PB_MessageRequester_Info)
Else
  OnErrorCall(@GetFileError())
EndIf

So the problem is at follow...
I try to program my file importer so, thad you can import an *.txt file as standart doc.txt (initialized),
but i want thad if the file is found, than show an message with the given file, but if not... than it must
be give an error, called "Fatal Error!", "Can't find the File"... as an MessageError.

But the problem is thad the error must be given if the file isn't found, but the exception error handling
does not works yet...

So can you try to find the problem and than correct my code, pleace?...
Thanks for code correction, Jamie.
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: [Windows Programming] File Exception Handling not Works

Post by wayne-c »

See comments in code below:

Code: Select all

;Make File Error
Procedure GetFileError()
  MessageRequester("Fatal Error!", "Cant find File", #PB_MessageRequester_Error)
EndProcedure


;Try to find File
File$ = OpenFileRequester("Import", "doc.txt", "Text (*.txt) | *.txt", 0)
If File$ 
  MessageRequester("File Info", File$, #PB_MessageRequester_Info)
Else
  ; not needed : OnErrorCall(@GetFileError())
  ; call GetFileError() directly:
  GetFileError()
EndIf
As you walk on by, Will you call my name? Or will you walk away?
Post Reply