Shop OBEX P1 Docs P2 Docs Learn Events
Trouble including a file in SX/B — Parallax Forums

Trouble including a file in SX/B

sstickelersstickeler Posts: 8
edited 2007-06-08 05:35 in General Discussion
Hi, I am trying to split my SX/B program into a couple of files to make things modular. For example, I want to put all my LCD routines into their own file so I can re-use them. For the LCD routines, I have one file that has constant and variable definitions and another file that has the subroutines.

I am trying to include the file with the constant and variable defs right after the device section in my main file. I am using LOAD "header.sxb' but I keep getting an error saying "header.sxb NO PROGRAM COMMAND USED".

Can someone help me figure out what I am doing wrong? Why would I need a PROGRAM command in a header file?

Thanks,
Scott

Comments

  • BeanBean Posts: 8,129
    edited 2007-06-06 10:46
    Scott,
    · The compiler is complaining that you haven't used the "PROGRAM label" command in your program.
    · If you could post the files we could assist you further.

    [noparse][[/noparse]edit] Are you trying to compile "header.sxb" ? That will give you the error. Just make a little test program that uses LOAD "header.sxb" to test the file.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com


    Post Edited (Bean (Hitt Consulting)) : 6/6/2007 1:29:26 PM GMT
  • sstickelersstickeler Posts: 8
    edited 2007-06-06 17:18
    Hi Bean.

    I have attached some test files that demonstrate the problem.

    The file "test.sxb" is my original file. This compiles with no errors.
    The file "test_new.sxb" is the same file but with some of the constants moved to another file "header.inc". I am trying to LOAD this file in the same location where the constants
    originally were and I get the error.

    Any help would be greatly appreciated! It appears the pre-processor is interpreting the header.inc file assuming it is a complete program instead of a piece of the whole.

    Thanks,
    Scott
  • BeanBean Posts: 8,129
    edited 2007-06-06 17:26
    Scott,
    It looks like it might be a bug in the compiler. I see what's going on, it includes the header.inc file, but the compiler checks at the end of compiling to make sure you have used the PROGRAM directive. It looks like it is performing that check when you "LOAD" a file (and it shouldn't). I will look into it deeper as soon as I can.

    If you can re-arrange your program so the PROGRAM directive comes before the LOAD directive, that should fix it for now.


    [noparse][[/noparse]Edit] I have verified that the compiler is in fact checking if a PROGRAM directive has been used after compiling the header.inc file. This will be corrected in the next release.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com


    Post Edited (Bean (Hitt Consulting)) : 6/6/2007 5:50:53 PM GMT
  • sstickelersstickeler Posts: 8
    edited 2007-06-06 18:07
    Thanks Bean. I'll try re-arranging some stuff to see if that helps. Glad to at least know what the problem is.

    -Scott
  • JonnyMacJonnyMac Posts: 8,940
    edited 2007-06-07 17:30
    You know, I find myself doing a lot of copy-and-paste between SX/B programs and for the book I thought I should explore LOADing external SX/B segments. I've attached the results of my experiment which save me the trouble of copy-and-paste, and do seem to work. I think the keys to this is remember that SX/B is a single-pass, compile-in-place compiler -- so you'll see that I've consider this in the way I created my files: one for the SUB/FUNC declarations and a second file for the code for those subroutines and functions.

    What my experiment counts on, however, is a consistent set of variables for subroutines and functions, and I document these requirements in my external files.

    I hope this helps.
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-06-08 00:33
    I wrestled with this same problem. You can read about it in the “SX/B - Possible File Inclusion BEFORE Program Statement?” thread.

    I wanted to keep things such as IO Pins, Constants, Variables and my ISR in separate files. All of these typically come before the PROGRAM directive. I was able to accomplish this by chaining these files together. So my main program loads the first file, which for me happens to hold my I/O pin definitions. The first file then loads the second file, which for me holds the definitions for all of my constants. At the end of this file it loads the next one which holds variables. And so on. The trick is that the last one to be loaded in this fashion needs to include the PROGRAM directive!

    After the PROGRAM directive is encountered you no longer need to chain your files.
    I am glad to read this will be improved in the next version. I have done it so often I do not give it much thought anymore!

    - Sparks
  • BeanBean Posts: 8,129
    edited 2007-06-08 00:39
    Sparks,
    Sorry I didn't realize the nature of the problem in your old post.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-06-08 00:46
    That’s ok, Bean. I did not realize it was a problem needing to be fixed!
    I only saw it as a problem with me understanding how things needed to be organized to get them to work the way *I* wanted to structure my programs!

    - Sparks
  • sstickelersstickeler Posts: 8
    edited 2007-06-08 05:35
    Thanks to the responses on this thread I was able to achieve what I was trying to do. I just moved my LOAD command below the PROGRAM directive in my main file and everything is ok. I managed to get all my LCD routines and definitions in one file so now I should be able to include this in future projects and import the LCD functionality when needed.

    -Scott
Sign In or Register to comment.