text.s + "whatever" not working.

Just starting out? Need help? Post your questions and find answers here.
superjacent
User
User
Posts: 27
Joined: Mon Oct 01, 2007 1:38 pm
Location: Melbourne, Australia
Contact:

text.s + "whatever" not working.

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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 ???
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :)
I may look like a mule, but I'm not a complete ass.
superjacent
User
User
Posts: 27
Joined: Mon Oct 01, 2007 1:38 pm
Location: Melbourne, Australia
Contact:

Post 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.
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Well, yes; that's what we've been discussing! :)
I may look like a mule, but I'm not a complete ass.
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

Whoops. I should have read more of the posts. :oops:
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

quidquid Latine dictum sit altum videtur
Post Reply