Page 1 of 1
text.s + "whatever" not working.
Posted: Mon Jul 14, 2008 2:12 pm
by superjacent
The following is from the book, Purebasic - A beginners guide, but the end result is not as per the book. As written, the message box appears, for me, under Vista, only refers to the last Text.s + "Error occurred in module..." part and only the variable portion, GetErrorModuleName(). That is the MessageRequester simply reports "Main Module".
Code: Select all
;Set the error handler
OnErrorGoto(?ErrorHandler)
;Trigger a classic 'divide by zero' error.
Null.l = 0
TestVariable.l = 100 / Null
;Handle any system error that occurs
ErrorHandler:
Text.s = "Error count:" + #TAB$ + #TAB$ + Str(GetErrorCounter()) + #CRLF$
Text.s + "Error ID number:" + #TAB$ + #TAB$ + Str(GetErrorNumber()) + #CRLF$
Text.s + "Error description:" + #TAB$ + #TAB$ + GetErrorDescription() + #CRLF$
Text.s + "Error occurred on line:" + #TAB$ + Str(GetErrorLineNR()) + #CRLF$
Text.s + "Error occurred in module:" + #TAB$ + GetErrorModuleName() + #CRLF$
MessageRequester("ERROR", Text)
End
If I comment out the last Text.s bit I then get a couple of the previous Text.s strung together, but not all.
I've directly copied the above code from the pdf file.
Any clues please.
Posted: Mon Jul 14, 2008 2:37 pm
by srod
Yes that is strange. Haven't checked on XP.
It would seem that GetErrorModuleName() wipes the string buffer.
Still, there is an obvious workaround :
Code: Select all
;Set the error handler
OnErrorGoto(?ErrorHandler)
;Trigger a classic 'divide by zero' error.
Null.l = 0
TestVariable.l = 100 / Null
;Handle any system error that occurs
ErrorHandler:
Text.s = "Error count:" + #TAB$ + #TAB$ + Str(GetErrorCounter()) + #CRLF$
Text.s + "Error ID number:" + #TAB$ + #TAB$ + Str(GetErrorNumber()) + #CRLF$
a$ = GetErrorDescription()
Text.s + "Error description:" + #TAB$ + #TAB$ + a$ + #CRLF$
Text.s + "Error occurred on line:" + #TAB$ + Str(GetErrorLineNR()) + #CRLF$
a$ = GetErrorModuleName()
Text.s + "Error occurred in module:" + #TAB$ + a$ + #CRLF$
MessageRequester("ERROR", Text)
End
Posted: Mon Jul 14, 2008 2:40 pm
by Rook Zimbabwe
I can't even get my compiler to allow a div by 0 error... What version are you using?
as a poke in the dark... have you tried using +Chr(10) instead of CRLF ???
Posted: Mon Jul 14, 2008 2:49 pm
by srod
You have to enable OnErrorLinesSupport (compiler options) and then create the exe for you to run.
**EDIT : the poke in the dark does not get around the fact that the function seems to wipe the string buffer!

Posted: Tue Jul 15, 2008 12:30 pm
by superjacent
Thanks, I'll put this one down to 'just one of those things' to watch out for. Even modifying as suggested, the whole snippet doesn't work as intended.
For future reference I suppose it's just a matter of assigning each of those error codes/messages to separate variables and then join them.
Posted: Wed Jul 16, 2008 1:40 am
by npath
It appears that the following two error-related procedures are clearing the memory buffer.
Code: Select all
GetErrorDescription()
GetErrorModuleName()
This is shown using this code:
Code: Select all
;Set the error handler
OnErrorGoto(?ErrorHandler)
;Trigger a classic 'divide by zero' error.
Null.l = 0
TestVariable.l = 100 / Null
;Handle any system error that occurs
ErrorHandler:
Text.s = "Error count:" + #TAB$ + #TAB$ + Str(GetErrorCounter()) + #CRLF$
MessageRequester("ERROR", Text)
Text = Text + "Error ID number:" + #TAB$ + #TAB$ + Str(GetErrorNumber()) + #CRLF$
MessageRequester("ERROR", Text)
Text = Text + "Error description:" + #TAB$ + #TAB$ + GetErrorDescription() + #CRLF$
MessageRequester("ERROR", Text)
Text = Text + "Error occurred on line:" + #TAB$ + Str(GetErrorLineNR()) + #CRLF$
MessageRequester("ERROR", Text)
Text = Text + "Error occurred in module:" + #TAB$ + GetErrorModuleName() + #CRLF$
MessageRequester("ERROR", Text)
End
Posted: Wed Jul 16, 2008 10:19 am
by srod
Well, yes; that's what we've been discussing!

Posted: Wed Jul 16, 2008 6:34 pm
by npath
Whoops. I should have read more of the posts.

Posted: Wed Jul 16, 2008 6:49 pm
by freak