Question about (x)include files

Just starting out? Need help? Post your questions and find answers here.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 644
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Question about (x)include files

Post by captain_skank »

Hi all,

I've used includes forever and have only now run into this problem and wonder if their is a workaround :

So normally i use

Code: Select all

XIncludeFile "C:\Users\MY_USERNAME\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"
Recently I wanted to do some work on another pc but had to change all the xincludes because of the username, which is a pain.

The compiler doesn't like it if i put different username xincludes in a IF THEN ELSE or SELECT CASE scenario,
it also throws a hissy fit if the xinclude is on e network drive/share and you cant use variable in xincludes either.

I do want to keep my file structure in a specified users directory though.

Any help appreciated.

cheers
Sirius-2337
User
User
Posts: 59
Joined: Sat May 14, 2011 10:39 am

Re: Question about (x)include files

Post by Sirius-2337 »

Code: Select all

#MY_USERNAME = "user01"

XIncludeFile "C:\Users\" + #MY_USERNAME + "\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"

;OR

XIncludeFile "\_includes\MY_INCLUDE.pbi"

;OR

#PC = 2

CompilerIf #PC = 1
  XIncludeFile "C:\Users\MY_USERNAME\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"
CompilerElseIf #PC = 2
  XIncludeFile "C:\Users\ANOTHER_USERNAME\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"
CompilerEndIf
User avatar
kenmo
Addict
Addict
Posts: 2070
Joined: Tue Dec 23, 2003 3:54 am

Re: Question about (x)include files

Post by kenmo »

Use relative paths

Code: Select all

; relative to the current file
XIncludeFile "myInclude.pbi"
XIncludeFile "includes/modules/myInclude2.pbi"
Or if you want to be able to instantly change your includes dir:

Code: Select all

#IncludesDir = "c:\Projects\MyIncludes\" ; change me!

XIncludeFile #IncludesDir + "myInclude.pbi"
XIncludeFile #IncludesDir + "includes/modules/myInclude2.pbi"
Note if you use the 2nd method, you can't Ctrl+DoubleClick to open an include file instantly.
User avatar
mk-soft
Always Here
Always Here
Posts: 6433
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Question about (x)include files

Post by mk-soft »

Normal Windows permission.

It is best to create your own folder (D:\Projects\Includes) where all users have access to it.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 644
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: Question about (x)include files

Post by captain_skank »

Thanks for the replies.

Looks like i'll have to follow mk-soft's advice and move my project or just the includes to a more generic location.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Question about (x)include files

Post by Marc56us »

Code: Select all

XIncludeFile "C:\Users\MY_USERNAME\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"
PB >= 5.60 :arrow: GetUserDirectory()

Code: Select all

XIncludeFile GetUserDirectory(#PB_Directory_Documents) + \MY_PROJECT\_includes\MY_INCLUDE.pbi"
See also: GetEnvironmentVariable() (Type SET in a CMD windows to see others variables)
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Question about (x)include files

Post by #NULL »

I you don't want to edit anything at all, you can try to use some compiler constants to define your project directories at compile time.

Code: Select all

;Debug #PB_Compiler_Home

#environment_1 = "/home/user/purebasic_571_lts/"
#project_1     = "/home/user/project/"

#environment_2 = "/home/userXYZ/purebasic_571_lts/"
#project_2     = "/home/userXYZ/project/"

CompilerIf #PB_Compiler_Home = #environment_1
    #project_path = #project_1
CompilerElseIf #PB_Compiler_Home = #environment_2
    #project_path = #project_2
;CompilerElse
;    #project_path = "<undefined>"
CompilerEndIf

CompilerIf Not Defined(project_path, #PB_Constant)
  CompilerError "Error: Could not determine #project_path."
CompilerEndIf

XIncludeFile #project_path + "inc/some.pbi"
You also could just set IncludePath instead of using a constant and use realtive paths in the include statements. This won't help you with permissions of course. It also requires the compiler home to be different on each of your systems, but you get the idea. Otherwise you could still do the same using the #PB_Compiler_File[...] constants by comparing them to hardcoded strings in your main file for example, so depending where/what the mainfile is you will include with different paths.
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Question about (x)include files

Post by #NULL »

@Marc56us
These are runtime functions and don't work at compile time, as is necessary for include statements.
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Question about (x)include files

Post by Joris »

Code: Select all

IncludePath ...
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply