I think some of you have tried to call any PB or API command and nothing happend. Now this small procedure may hopefully help you to find the problem Good Luck! Feedback would be nice!
;-------------------------------------------------------------------------------------
; P u r e B a s i c v4 S h o w - A P I - E r r o r ( )
; -------------------------------------------------------------------------------------
;
; Description: This function examines, what was wrong with the last command call by
; API/PB like if nothing happens again! It returns a suitable error
; message string in your national language!
;
; Function: ShowAPIError (CheckReturnValue)
;
; Parameters: CheckReturnValue
;
; Enter here the value, where you have saved the return value of the
; API/PB command you have called and want to check.
;
; ReturnValue: A string including the message text will be returned.
;
; -------------------------------------------------------------------------------------
; Program by va!n aka Thorsten Will - 26/April/2006
; -------------------------------------------------------------------------------------
Procedure.s ShowAPIError (CheckReturnValue)
Buffer.s = Space (4096)
NumberOfChars = FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, CheckReturnValue, 0, Buffer.s, Len(Buffer.s), 0)
ProcedureReturn Left (Buffer.s, NumberOfChars-2)
EndProcedure
; -------------------------------------------------------------------------------------
; S m a l l e x a m p l e
; -------------------------------------------------------------------------------------
result = Sleep_(2)
Debug ShowAPIError(result) ; No Error
result = RegOpenKeyEx_(0, 0, 0, 0, 0)
Debug ShowAPIError(result) ; Error
result = MessageBox_(0,0,0,0)
Debug ShowAPIError(result) ; Error (after pressing the MsgBox)
;-------------------------------------------------------------------------------------
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Procedure.l die(msg.s = #NULL$)
If msg = #NULL$
msg = Space(4096)
FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError_(), 0, msg, Len(msg), 0)
EndIf
MessageRequester(GetFilePart(#PB_Compiler_File), msg, #MB_OK|#MB_ICONERROR)
EndProcedure
If ReadFile(0,"no-file.txt") Or Die()
CloseFile(0)
EndIf
looks good, no ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
ohhh... i personally didnt know that it was already published on this forum, years ago... maybe, because i am trying now more and more to get in touch with the API instead only PB commands...
I found the tip on the web of a VB site and tried to get it work... ^^