Announcement

Collapse
No announcement yet.

using include file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • using include file

    I have several programs using the same UDT's. When a change is made in a UDT in one program, I have to go make the same change in other programs using that same UDT.
    So--I copied all the UDT's being used by all the programs into a .inc file, and #included that file in all my programs.

    So far so good. However, it seems to take twice as long to compile the program in the PB editor as it did before using then include file. Also, I get "file not responding" when compiling to run, and the file is dumped to my tool bar instead of showing on the screen as usual.

    Any thoughts would be appreciated.

    John Tate

  • #2
    Howdy John!
    I've not seen the problem myself.

    How large is the include file?

    Can you make a sample version that demonstrates the problem, that we can run on our own PCs?

    And, I don't know what this means ...
    ... file is dumped to my tool bar instead of showing on the screen as usual.
    Can you tell me more?

    Comment


    • #3
      Have you any Compiler directives in the INCLUDE file that are duplicated in the .BAS file that calls the included file?
      Rod
      "To every unsung hero in the universe
      To those who roam the skies and those who roam the earth
      To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

      Comment


      • #4
        I am in the PB editor. I compile to run the testinclude.bas file. The first compile works as normal. Any further compiles send the complied file to the tool bar at the bottom of my monitor. I click on it and it runs fine.

        Any standalone .exe file works as it should.

        See what you think.

        John Tate
        Attached Files

        Comment


        • #5
          Hey John,
          The bas file downloads as an HTML file for me. Can you confirm that it is a PowerBASIC source code file?

          Comment


          • #6
            It appears to be the PB home page html file.

            However, there appears to be nothing wrong with the $INCLUDE file, it loads and compiles fine in more than one of my programs, and the programs run as they should. Ergo, the issue must be in the missing .bas file.
            Rod
            "To every unsung hero in the universe
            To those who roam the skies and those who roam the earth
            To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

            Comment


            • #7
              here is the simple test file that I used to show my problem.


              #COMPILE EXE
              #DIM ALL
              #INCLUDE "TFUDT.INC"
              FUNCTION PBMAIN () AS LONG
              LOCAL ctemp AS customer
              ctemp.custname = "John Tate"

              MSGBOX ctemp.custname
              END FUNCTION

              John Tate

              Comment


              • #8
                Now I cannot make the test file misbehave at all. I will work on it some more tomorrow.

                John Tate

                Comment


                • #9
                  I'm not seeing any difficulty with it here. I get the MSGBOX right where it should be.

                  I wonder if your IDE settings are the culprit, as per the help file:
                  If FileSpec does not include a path, the compiler scans the search path for each #INCLUDE file before checking the current (default) directory. For the IDE, the search path can be set in the Compiler Preferences tab in the Options dialog. The search path can also be specified when compiling from the command-line by using the /I Include option. The search path can contain one path or multiple paths to scan. If multiple paths are used, they are separated by a semicolon (.
                  Do you have a directory specified under the WINDOWS/OPTIONS/COMPILER tab?
                  Rod
                  "To every unsung hero in the universe
                  To those who roam the skies and those who roam the earth
                  To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                  Comment


                  • #10
                    I am using PB 10.4. This is my first use of an include file. I tried to add the path specifically to my default folder, but it will not let me do that. The only path I see to "includes" is "C:\PBWin10\WinAPI".

                    Comment


                    • #11
                      Be sure to indicate

                      #Include ONCE "myfile.inc"

                      It tells the compiler to not re-include a file that has already been included...

                      Helps prevent "nested includes"...


                      -John

                      Comment


                      • #12
                        This is my first use of an include file. I tried to add the path specifically to my default folder, but it will not let me do that. The only path I see to "includes" is "C:\PBWin10\WinAPI".
                        To add another path to search, click on the button to the right of the textbox where the "C:\PBWin10\WinAPI" appears. It will open another dialog that has a button "Add Folder". Click that and it will open yet another dialog to select the folder you want to add.

                        FWIW, I have never added another path to mine until I tried it just now to make sure I explained it correctly. I leave my home made includes in the same directory as the file that uses them resides.
                        Rod
                        "To every unsung hero in the universe
                        To those who roam the skies and those who roam the earth
                        To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                        Comment


                        • #13
                          How much longer? That is, does it really matter?

                          And is it perhaps only the the FIRST compile, which has been my experience with #INCLUDE files? (I use the PB IDE).

                          Comment


                          • #14
                            I only mentioned the compile time increase because it is different than what I am used to.
                            I opened all the files using the new #include file and saved them as a project. Now when I open the project, all the files are opened in the IDE as expected. However, when I select a file to edit and recompile, only one file is compiled, which is not the file I was working on. I am sure the project feature is supposed to work better than that.

                            What in the world did I do wrong?

                            My goal was to have the project open all the files using the edited #include so I would not forget which programs needed to recompiled.

                            I am using pb 10.04, Win 7 home premium.

                            Comment


                            • #15
                              > I am sure the project feature is supposed to work better than that.

                              Wrong feature. For your "other files" you want to "Run/Set Primary Source File." Now when you Run/Compile [and Execute] with your #INCLUDE file as the active file, it will compile starting with that Primary Source File.

                              I have no idea if this is saved as part of the project or not, but I'm sure you are are about to find out... and will let us know.

                              MCM

                              Comment


                              • #16
                                Thanks, MCM.
                                Here is what I have come to understand.
                                I can open as many of .bas files I want, including the .inc file, in the IDE.

                                I can save as project all these files under a project name

                                I can make a change in one of the .bas files, then run to execute the .inc file, with the changed .bas file as primary file.

                                The .bas file will be compiled with changes, and I am able to run it from the toolbar.

                                However, no other file in the project will be compiled in this scenario.

                                I was under the impression that all files in the project would be compiled when the .inc was run to execute.

                                is my understanding of the project feature correct now?

                                Thanks for putting up with my density.

                                Comment


                                • #17
                                  I was not aware of any PowerBASIC-supplied feature to handle multiple compilations (multiple executables) in a single pass, especially in the IDE (when I specify compile and run, which one is supposed to run?) .

                                  I am pretty sure some of the third-party guys offer "multiple-executable project" support.

                                  I am also pretty sure a good number of folks create a command file (*.cmd) and accomplish this goal by invoking the command-line compiler multiple times.

                                  FWIW...,
                                  " I was under the impression that all files in the project would be compiled when the .inc was run to execute...

                                  ... then run to execute the .inc file,...
                                  Just as a matter of style, you probably don't want to use the file extension *.INC for the primary module for executable (#COMPILE EXE, #COMPILE DLL, #COMPILE SLL) modules. I think the PB IDE has some 'funkiness' regarding file extensions.

                                  I hope you did not mean compile and execute ONLY the procedures in the *.INC file but it almost reads like that.

                                  For the few times I've used PB 'projects' I usually have one (1) *.BAS for my primary source file, and multiple *.INC files which are #INCLUDEd in that *.BAS file.

                                  Sometimes I'll use a *.BAS as an #INCLUDEd file, but then it has no entry point function (WinMain/PbMain) and no compiler directives. All it is is procedures used by the primary module.

                                  But... whatever works for you.

                                  MCM

                                  Comment


                                  • #18
                                    Thanks to all who responded to my problem.


                                    I can reach my goal easier than before by opening the project, realizing that each .bas file has to be compiled. At least, all the files are visible and will not be forgotten.

                                    John Tate

                                    Comment


                                    • #19
                                      John,
                                      If you wish to combine several .BAS files into a single compiled program, you may combine them without multiple compiles as follows:
                                      Pick a Main file.
                                      Add all the other file names to the Main file as follows:
                                      #INCLUDE "secondfilename.bas"
                                      #INCLUDE "thirdfilename.bas"
                                      ...etc
                                      The compiler will include all the include files in the final compilation if the routines are needed by the Main file. However, there are some rules...
                                      In the other files, eliminate all PBMain routines (only ONE is allowed per compiled program); remove all #COMPILE EXE and all redundant #INCLUDE statements and directives in the include files. If they appear in the Main file, they will be extended into the included .BAS files. Watch ALL GLOBAL variables because the scope will now encompass ALL included files! You do not need to compile the included files; they will be included and compiled when you compile the Main file. If any errors are detected in any of the files, the file text and location will be displayed along with the error.

                                      You will have problems initially with redundant or unnecessary syntax because, in the final analysis, the include files are only a collection of functions and subs used in conjunction with the Main file. Just look at the problems described when compiling and make the necessary changes. Remember, do NOT try to compile include files!

                                      I started this way because my Main file was getting too large and ungainly to handle, so I added the include files to segregate various function and their windows for such things as setup, viewing, printing, etc. I even added an include file for all my GLOBAL variables and UDTs, named "globvars.bas".
                                      Following is a simple example of a Main file and an include file. You only have to compile the Main file, "GetPath.bas", and the include, "GetStuff.bas", will automatically be added to the compilation.

                                      Main File: "GetPath.bas"
                                      Code:
                                      #COMPILE EXE
                                      #DIM ALL
                                      #INCLUDE "WIN32API.INC"
                                      #INCLUDE "GetStuff.bas"
                                      
                                      FUNCTION PBMAIN () AS LONG
                                        LOCAL a AS STRING
                                        a = GetDataPath
                                        MSGBOX a
                                      END FUNCTION
                                      Include file: "GetStuff.bas"
                                      Code:
                                      FUNCTION GetDataPath() AS STRING
                                      '-------------------------------------------------------------------------------
                                      ' Get the data path for common data 
                                      '-------------------------------------------------------------------------------
                                        LOCAL iRet AS LONG, dwFlags AS DWORD
                                        LOCAL szBaseFolder AS ASCIIZ * %MAX_PATH
                                        dwFlags = %SHGFP_TYPE_CURRENT   ' choices are _TYPE_CURRENT or _TYPE_DEFAULT (user may move this folder temporarily)
                                        iRet = ShGetFolderPath (BYVAL %NULL,(%CSIDL_COMMON_APPDATA), BYVAL %NULL, dwFlags, szBaseFolder)
                                        FUNCTION = szBaseFolder
                                      END FUNCTION
                                      Last edited by Michael Boho; 29 Aug 2015, 01:45 AM. Reason: clarification
                                      It's impossible to make anything foolproof because fools are so ingenious.

                                      Comment


                                      • #20
                                        Thanks M. Boho for the response.
                                        I will look into what you propose later this year, since I will be in the process of rewriting most of the .bas programs. A lot of the programs were written during my first tries at programming for Windows.

                                        I have rewritten one program, and the lines of code are less than half of the original, accomplishing the same tasks. I am a much better windows programmer now than a few years ago.

                                        Thanks again to all.

                                        Comment

                                        Working...
                                        X