Shop OBEX P1 Docs P2 Docs Learn Events
Include statements — Parallax Forums

Include statements

slcottslcott Posts: 27
edited 2010-01-08 06:00 in General Discussion
I would like to use the include statement for a 1000 line program I've built. I'm doing some refactoring and ideally would like to break it into two files. Does anyone have any advice on how to use the Include statement because I am trying to use it to separate out some functions from my main file and get interesting errors. These include 2009-12-22_2038.png
917 x 922 - 70K

Comments

  • PJMontyPJMonty Posts: 983
    edited 2009-12-23 02:18
    Slcott,

    I'm guessing that the file "fpu.sxb" is one of the included files, and that you're trying to compile it by itself. If so, then the reason you're getting errors is that the compiler needs the declarations made in the main source file. There are two solutions. The first is to always make sure you compile the main program and let it tell the compiler to include the other files. This is a pain because you constantly have to switch active files in the IDE. The other is to use the (sadly, still undocumented) "Top File" feature of the IDE.

    Basically, the "Top File" feature was implemented for exactly this situation. You want to have multiple include files, and you also want to be able to hit the compile button while working on any of the them. To do this, you need to tell the IDE which file is the "top" file and then it will do the rest.

    Here's what you need to do.

    1 - Load whatever file is your "top" file.
    2 - Right click in the file list pane on the left side of the IDE.
    3 - Left click the menu option that says "Set as Top File"

    The attached image shows the menu in operation.

    From that point on, any time you hit the compile button (of hotkeys), the IDE will offer to use the "Top" file as the one to compile from. Click "Yes" or hit the Enter key and the IDE will do the rest. The IDE keeps track of your topfiles using the registry. This means that whenever you load a known "Top" file, the IDE will offer to make it the current "Top" file. Note that you can only have one "Top" file open at a time in the IDE. If you ever decide to convert the project back into a single file project, you can right click and choose the menu option that says "Set as normal File."

    Thanks,
    PeterM
    878 x 524 - 125K
  • slcottslcott Posts: 27
    edited 2009-12-24 13:14
    is there a template you follow to use the include directive? that might be easier to follow. i'm trying to organize my program this way: main file, subroutines file. where do the declarations go? with the same file they are in or the main file? i keep getting the following error. is there a way to suppress it?
    240 x 165 - 3K
    656 x 766 - 15K
  • BeanBean Posts: 8,129
    edited 2009-12-24 13:48
    If the files are SX/B then use the LOAD command to load the SX/B files instead of using INCLUDE for the SRC files.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    PropBASIC home page www.propbasic.com
    ·
  • PJMontyPJMonty Posts: 983
    edited 2010-01-07 20:31
    slcott,

    1 - I take a good chunk of time to explain how to use an un-documented feature and you don't even say, "Thanks." Seriously, how hard is it to type type six letters and acknowledge that someone took time out of their day to help a complete stranger?

    2 - It's not an error message. Where does it say "Error" on that dialog? It's a dialog to make sure that people don't forget they have a top file loaded. What if you loaded another project, forgot you still had a top file in the IDE, and then hit "Compile"? If that happened, you'd be be posting that the IDE refuses to compile your program.

    3 - I anticipated this question when I wrote my original reply to you, but apparently you skipped over that part of my detailed reply. Here's the relevant portion of the original post - "From that point on, any time you hit the compile button (or hotkeys), the IDE will offer to use the "Top" file as the one to compile from. Click "Yes" or hit the Enter key and the IDE will do the rest."

    4 - This concludes my involvement with this thread.

    PeterM
  • JonnyMacJonnyMac Posts: 9,077
    edited 2010-01-07 20:48
    I know it's not popular to read the documentation we create, so here's the hand-holding you're looking for. It is my preference to break load-able material into two parts 1) for declarations of subs and funcs, and 2) actual working code for subs and funcs. See attached.

    Sorry... the forums giving trouble and will not let me upload .sxb files without changing the extension; remove the .txt from the files before use (I've tried two pcs and two different browsers).
  • BeanBean Posts: 8,129
    edited 2010-01-08 02:16
    Jon,
    · I was able to upload them. Weird ???

    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
  • ZootZoot Posts: 2,227
    edited 2010-01-08 06:00
    It's a browser issue -- some browsers will not handle the file as a text mime-type (even though they are text files) because of the extension. The forum's server-side app only allows certain non-text data types, e.g. png and jpg; when the browser presents the .SXB or .SRC file as a binary type, it gets rejected.

    P.S. -- to PJMonty -- is top file only for INCLUDEs? Or will it work for LOADs also? The original question probably was about LOAD (as the project is SXB) even though the word "include" was used.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php


    Post Edited (Zoot) : 1/8/2010 6:09:39 AM GMT
Sign In or Register to comment.