Author Topic: $IF VERSION THEN $ERROR  (Read 3196 times)

0 Members and 1 Guest are viewing this topic.

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
$IF VERSION THEN $ERROR
« on: January 27, 2021, 06:53:44 am »
QB64 1.5 will feature a new metacommand and a new pre-compiler value. The below example shows them both:
Code: [Select]
$IF VERSION < 1.5 THEN
    $ERROR Requires QB64 version 1.5 or greater
$END IF

VERSION evaluates to the QB64 compiler version. $ERROR can be used in a $IF block to give a compilation error with a helpful message to the user if the programmer knows they will be using new features. You could also use $ERROR if you program is Windows-only or Linux-only, for instance. VERSION could also be used to implement a section of code two different ways if you're trying to work around differences in behaviour in QB64 versions.

See wiki for further details.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: $IF VERSION THEN $ERROR
« Reply #1 on: January 27, 2021, 08:29:01 am »
Perfect! I love this idea. You guys are great.
Shuwatch!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: $IF VERSION THEN $ERROR
« Reply #2 on: January 28, 2021, 07:45:00 am »
Is the build process broken?

Was going to test the $ERROR thing, but the dev-build download is still git e3b9c46 from Jan/27.

Shouldn't it be git f7cd2b2 or 65beb28 from Jan/28 already ??
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

FellippeHeitor

  • Guest
Re: $IF VERSION THEN $ERROR
« Reply #3 on: January 28, 2021, 08:02:56 am »
Checking. Thanks for pointing it out.

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: $IF VERSION THEN $ERROR
« Reply #4 on: January 28, 2021, 08:12:18 am »
Just see, it affects the Windows downloads only.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: $IF VERSION THEN $ERROR
« Reply #5 on: January 28, 2021, 08:40:15 am »
Quick question with all these new error commands:

Since we can generate actual error messages now ( _ERRMESSAGE$, or such, I think), is there some way to set custom messages to go with the codes?

For example, ERROR 5 might give us an error message of “ERROR 5: Illegal Function Call”, but a custom error of 128 would just say, “ERROR 128:”

Is there something like an _CUSTOMERROR$(errNum, errMes$), which an user can use   to set those custom errors?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: $IF VERSION THEN $ERROR
« Reply #6 on: January 28, 2021, 09:18:42 am »
If you have a custom error code it’s likely because you have a custom error handler.

FellippeHeitor

  • Guest
Re: $IF VERSION THEN $ERROR
« Reply #7 on: January 30, 2021, 05:18:22 pm »
@SMcNeill I stand corrected, we already have _ASSERT: http://www.qb64.org/wiki/ASSERT

Code: QB64: [Select]
  1. $ASSERTS:CONSOLE
  2.  
  3.     a = INT(RND * 10)
  4.     b$ = myFunc$(a)
  5.     PRINT a, , b$
  6.     _LIMIT 3
  7.  
  8. FUNCTION myFunc$ (value AS SINGLE)
  9.     _ASSERT value > 0, "Value cannot be zero"
  10.     _ASSERT value <= 10, "Value cannot exceed 10"
  11.  
  12.     IF value > 1 THEN plural$ = "s"
  13.     myFunc$ = STRING$(value, "*") + STR$(value) + " star" + plural$ + " :-)"

It's an on-spot error handler which allows for a custom message.