Author Topic: Library Code Exclusion  (Read 4642 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Library Code Exclusion
« on: November 21, 2019, 12:21:19 pm »
If you guys are like me, and code everything into library snippets to reuse it over and over, you probably end up finding that some of your essential code ends up going into multiple libraries and then tossing errors when you make use of those libraries together.

Here's a solution which works (as long as $IF works as it should for us -- see my previous post today about correcting a glitch with it) in this case:

Code: QB64: [Select]
  1. $IF EXT = UNDEFINED THEN
  2.     $LET EXT = TRUE
  3.     FUNCTION ExtendedTimer##
  4.     DIM m AS INTEGER, d AS INTEGER, y AS INTEGER
  5.     DIM s AS _FLOAT, day AS STRING
  6.     day = DATE$
  7.     m = VAL(LEFT$(day, 2))
  8.     d = VAL(MID$(day, 4, 2))
  9.     y = VAL(RIGHT$(day, 4)) - 1970
  10.     SELECT CASE m 'Add the number of days for each previous month passed
  11.     CASE 2: d = d + 31
  12.     CASE 3: d = d + 59
  13.     CASE 4: d = d + 90
  14.     CASE 5: d = d + 120
  15.     CASE 6: d = d + 151
  16.     CASE 7: d = d + 181
  17.     CASE 8: d = d + 212
  18.     CASE 9: d = d + 243
  19.     CASE 10: d = d + 273
  20.     CASE 11: d = d + 304
  21.     CASE 12: d = d + 334
  22.     END SELECT
  23.     IF (y MOD 4) = 2 AND m > 2 THEN d = d + 1 'add a day if this is leap year and we're past february
  24.     d = (d - 1) + 365 * y 'current month days passed + 365 days per each standard year
  25.     d = d + (y + 2) \ 4 'add in days for leap years passed
  26.     s = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
  27.     ExtendedTimer## = (s + TIMER)

ExtendedTimer is something which I use in a lot of code, and as such, it gets included into a lot of libraries.  By coding it like this, QB64 only includes it in my programs once -- no matter how many libraries it's contained within -- and doesn't toss me "Name already in use" errors and whatnot." 

It's a simple enough little habit to get into using with our library code, and it'll prevent the issues with duplicate copies being in multiple libraries. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!