Author Topic: include directive  (Read 3315 times)

0 Members and 1 Guest are viewing this topic.

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
include directive
« on: October 20, 2020, 04:02:07 pm »
Hello

I have put some code in a .bi file. i cant gosub the routine it gives label not define how to i get arount this


Badger

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: include directive
« Reply #1 on: October 20, 2020, 04:19:06 pm »
Hi badger

try this code and say me if it works for you

1. create a file saved as included.bm in the same folder of  main code file
opern QB64 and paste this code
Code: QB64: [Select]
  1. CLS , 1
  2. PRINT "I am here... before TRY1"
  3. Try1:
  4.  
  5. FOR a = 1 TO 5
  6.     PRINT a
  7. IF go = 1 THEN RETURN
  8.  
  9.  
now save it as included.bm, and then press Ctrl+N to get a new file and paste this other code into it
Code: QB64: [Select]
  1. '$include:'included.bm'
  2. go = 1
  3. CLS , 4
  4. PRINT "I am in main.."
  5. PRINT " Now I go to TRY1"
  6. GOSUB Try1
  7.  
  8.  
now press F5 to run code! It works fine...
Programming isn't difficult, only it's  consuming time and coffee

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: include directive
« Reply #2 on: October 20, 2020, 04:25:05 pm »
hey there

yes that worked here is the code i am trying to use

badger

include file is opening.bi
Code: QB64: [Select]
  1. REM ***********************************************************
  2. REM **** variable defines for all programs ********************
  3. REM ***********************************************************
  4. REM ***********************************************************
  5.  
  6. REM ***********************************************************
  7. REM **** opening screen ***************************************
  8. REM ***********************************************************
  9. opnscr:
  10. DIM irow AS INTEGER, icnt AS INTEGER, icstart AS SINGLE, icend AS SINGLE
  11. DIM ixrot AS INTEGER, iyrot AS INTEGER, iscale AS INTEGER
  12. _FULLSCREEN 'full screen optional
  13. icstart = 0: icend = 8 * ATN(1)
  14. ixrot = 6: iyrot = 60: iscale = 4
  15. irow = 1
  16. CIRCLE (320, 240), 15, 9: PAINT STEP(0, 0), 9
  17.     FOR i = icstart TO icend STEP .04
  18.         x = 300 + (iscale * 40 - (irow * ixrot)) * COS(i)
  19.         y = 200 + (iscale * 40 - (irow * iyrot)) * SIN(i)
  20.         icnt = icnt + 1
  21.         COLOR 7: _PRINTSTRING (x, y), "Joyce's Bridal", 0 'display
  22.         IF icnt = LEN(text$) * 8 THEN icnt = 0: EXIT DO
  23.         _DISPLAY
  24.         COLOR 0: _PRINTSTRING (x, y), "Joyce's Bridal", 0 'erase
  25.         _DELAY 0.06
  26.     NEXT
  27. LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit
  28.  
  29.  

here is the code i am trying to run


Code: QB64: [Select]
  1. REM ********************************************************
  2. REM **** test to save one to many records ******************
  3. REM ********************************************************
  4.  
  5. REM ********************************************************
  6. REM **** include statements go here ************************
  7. REM ********************************************************
  8. 'include: 'opening.bi'
  9. REM ********************************************************
  10. GOSUB opnscr
  11. INPUT "first name "; sa
  12. INPUT "last name  "; sb
  13. INPUT "some data  "; sc
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  



Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: include directive
« Reply #3 on: October 20, 2020, 05:45:34 pm »
GOSUBs have to be in same same module or SUB or FUNCTION routine as the call to it.

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: include directive
« Reply #4 on: October 20, 2020, 05:48:58 pm »
bplus

i was thinking that i will change my way of thinking


badger

my mind is molasses today

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: include directive
« Reply #5 on: October 20, 2020, 05:51:06 pm »
You could make openScr a SUB (not GOSUB) and then INCLUDE file (usu .BM) at the bottom of the code using the .BM file.

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: include directive
« Reply #6 on: October 20, 2020, 05:52:34 pm »
bplus

thats an idea thanks it will only be used once so that will work


Badger

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: include directive
« Reply #7 on: October 20, 2020, 06:00:50 pm »
Here's how it works:
Code: QB64: [Select]
  1. ' save as open.bm
  2. SUB openScr
  3.     SCREEN 12
  4.     DIM irow AS INTEGER, icnt AS INTEGER, icstart AS SINGLE, icend AS SINGLE
  5.     DIM ixrot AS INTEGER, iyrot AS INTEGER, iscale AS INTEGER
  6.     _FULLSCREEN 'full screen optional
  7.     icstart = 0: icend = 8 * ATN(1)
  8.     ixrot = 6: iyrot = 60: iscale = 4
  9.     irow = 1
  10.     CIRCLE (320, 240), 15, 9: PAINT STEP(0, 0), 9
  11.     DO
  12.         FOR i = icstart TO icend STEP .04
  13.             x = 300 + (iscale * 40 - (irow * ixrot)) * COS(i)
  14.             y = 200 + (iscale * 40 - (irow * iyrot)) * SIN(i)
  15.             icnt = icnt + 1
  16.             COLOR 7: _PRINTSTRING (x, y), "Joyce's Bridal", 0 'display
  17.             IF icnt = LEN(text$) * 8 THEN icnt = 0: EXIT DO
  18.             _DISPLAY
  19.             COLOR 0: _PRINTSTRING (x, y), "Joyce's Bridal", 0 'erase
  20.             _DELAY 0.06
  21.         NEXT
  22.     LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit
  23.     COLOR 15
  24.  
  25.  
  26.  


Code: QB64: [Select]
  1. REM ********************************************************
  2. REM **** test TO save one TO many records ******************
  3. REM ********************************************************
  4.  
  5. openScr
  6.  
  7. INPUT "first name "; sa
  8. INPUT "last name  "; sb
  9. INPUT "some data  "; sc
  10.  
  11. REM ********************************************************
  12. REM **** include .BM files go here ************************
  13. REM ********************************************************
  14. '$include: 'open.bm'
  15. REM ********************************************************
  16.  

« Last Edit: October 20, 2020, 06:17:16 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: include directive
« Reply #8 on: October 20, 2020, 06:11:05 pm »
Quote
thats an idea thanks it will only be used once so that will work

Yeah I am thinking only code you might want to use in different app to put that in .BI's and .BM's

Code unique to app should just be used in the app maybe as SUB to get it out of way or unclutter main module.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: include directive
« Reply #9 on: October 21, 2020, 01:15:50 am »
I have never used INCLUDE because I have enough trouble keeping track of the data files
my programs require.  To split up source code is, methinks, only for way advanced coders.

It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: include directive
« Reply #10 on: October 21, 2020, 04:30:19 pm »
Hi badger

I think that the fantastic suggestions of Bplus and RichardFrost are the real solution of your issue!

Nevertheless standing on your original code and on the will to use a GOSUB and a included file...
your first mistake is the line 8 of the main program
Code: QB64: [Select]
  1. 'include: 'opening.bi'  
you have eaten $ at the beginning of (mistyping) $include'namefile'
after this correction now if you double click on this line of code in QB64 IDE you get a second window that show you the included file.
BUT if you compile this code you get ERROR return without GOSUB.... so you must run the RETURN instruction into the included file at line 35 of it only after a call to it... to do this you must follow my example using an IF THEN with a flag activated each time you call GOSUB to that label...
this feedback is just to show the logic that you have used behind the construction of your program with GOSUB and $include:'  '.

At the place of doing all these workaround you can use a closed block of code like SUB/END SUB or FUNCTION / END FUNCTION, more  flexible and powered by local variables.

Good Coding
Programming isn't difficult, only it's  consuming time and coffee

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: include directive
« Reply #11 on: October 22, 2020, 06:31:23 pm »
TempodiBasic

Thanks for your input. I figured out that i left out the $ symbol. I also needed to use a .bm file instead it would have worked i think. I have an logic error i am tracking down i need to setup what i call a flag veriable to direct the software to ware it needs to go. I have not been feeling well due to arthritis and the weather ugg i hate multiple long rainy days it hurts and my mind turns to mush due to the fact i get really tired and sleepy all day.

i will be back in the sadle i hope tomorrow LOL

Just want to take a minute to say Thanks for all your and every ones help. Your grasp on the qb64 environment is amazing as well as your grasp on programming abilities in general.

Badger