BASIC

Author Topic: Exit with message  (Read 2906 times)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Exit with message
« on: 2009-Apr-21 »
It would be good to have the equivalent of the "die" perl command so that you can abort the program with an error message. For example it would be good to be able to easily output "Error : Failed to set graphics mode" or similar.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10675
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Exit with message
« Reply #1 on: 2009-Apr-21 »
Code: GLBasic [Select]
FUNCTION Die: message$
BLACKSCREEN
PRINT message$,0,0
SHOWSCREEN
KEYWAIT
END
ENDFUNCTION
 

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5004
  • O Rly?
    • View Profile
Re: Exit with message
« Reply #2 on: 2009-Apr-21 »
Win32(on a separat gbas):

Code: GLBasic [Select]
INLINE
    extern "C" {
        DECLARE_ALIAS(exportMessageBoxA, "user32.dll", "MessageBoxA", (void*, const char*, const char*, unsigned int), int);
    } // close the extern "C"
ENDINLINE


FUNCTION Win32MessageBox: text$, caption$
INLINE // of course, GLBAsic does not know about "exportMessageBoxA" - only INLINE does
   if(exportMessageBoxA)
      return exportMessageBoxA(0, text_Str.c_str(), caption_Str.c_str(), 0);
ENDINLINE
ENDFUNCTION
 

Thats a WinApi-Messagebox :)

I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Exit with message
« Reply #3 on: 2009-May-28 »
Thanks for the WinApi call Schranz0r - that will be useful.

But say for example you tried to initialise a 1024x768x32 mode and the graphics card didn't support it. How would you display a error message with that?

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5004
  • O Rly?
    • View Profile
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Exit with message
« Reply #5 on: 2009-May-28 »
Cool, that will be helpful.

I was hoping though for a generic error message command. It seems that there really isn't much error handling in GLBasic and I would prefer to be able to catch and handle errors rather than having the program ignore them :-
eg. If any of the following fail
* You tried to load a graphic that doesn't exist
* You tried to write data to the network when the network connection had closed
* You tried to save data to a file and the save failed (full disk etc)
etc

I would like to be able to get return codes on commands that have a good chance of failing (pretty much the input / output to devices commands)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10675
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Exit with message
« Reply #6 on: 2009-May-28 »
OK, sounds like a good idea. Implementing a "lastError$()" function, that returns somthing like:
"001 File not found", where you could either cast it to a number to do error checking, or just display the text.

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: Exit with message
« Reply #7 on: 2009-May-28 »
Awesome - cheers Gernot!!!