External GLBasic Function Calls?

Previous topic - Next topic


Hi all,

I've scoured the search fields but couldn't find any threads directly related to my question.

I have written some really handy personal functions in GLBASIC, which may come in handy for future projects. Some of the functions are quite beefy in size, if you know what I mean, so it would be nice to move them off program and call them as needed using something similar to the "include" command, used for C++ code. Does GLBASC support some form of this, or will I just have to cut and paste my BASIC functions into future projects? An ability to call external GLBASIC functions, and compose my own personal libraries would streamline future programs; so I thought it was worth asking about.



HI CW, I don't know if this can help you...
In example if you do your new functions in another file like a .gbal source, you can add this file whitout problems...
It's similar to do a Require  , this command it's for import C and .mm files...

But if you do some functions and after you want add to your actual project only goes to the left of the screen , on you have the indexes functions, the name of the file browser.. then here you clik in right mouse and then load this file saved proviously like a gbal... this it's the standar extension for source files...

Another way you can compile your functions like a .DLL...

I don't know if can be helpfull... :-[



Hi Mental,

Thanks for the reply, but I'm not sure I follow. Check me on this.

Let's say I have a simple function, such as:

Code (glbasic) Select

Return RGB(128,128,InBlue)

which I have saved as "SetRGB.gbl" to my project folder.

Now, in a future program I want to use the function. What would I do? Copy the .gbl file to my project folder and then code Something like:

Code (glbasic) Select

DRAWRECT 100,100,50,50,SetRGB(250)

Should this work?
I tried it and it returns the error message:
Quote*** Configuration: WIN32 ***
GPC - GLBasic Precompiler V.9.829 SN:bda59dcb - 2D, WIN32
"TinkerToy.gbas"(1) warning : Demo mode: This command would require "GLBasic SDK premium"  : REQUIRE
"TinkerToy.gbas"(4) error : call to undefined function : SetRGB

Would this work with GLBasic SDK premium?
Or maybe I should copy the "SetRGB.gbas" file over instead (for GLBasic SDK premium version, to use the REQUIRE command.)
Can you give an example that would work, so that I can see the method? Thx!


No sorry for my bad english.... I think I confused beacuse I have my file list and functions in left of the screen, not at the rigth.. :whistle:

I put your same example:

But I attach in a .rar file, you can see better into your GLbasic...

In this project you will see 2 sorce files, 1 it's the main file, and the other it's the library...

I think whit the image I add , you can look more clear...

Another way how I comment before, it's do a .DLL file, but I never uses at this manner...

Regards, and if you have any question more, please ask... or someone sure will reply too much better than me...


Thanks Mentalthink,

I will study the screen image you gave me tomorrow. (It's late here.)
And don't worry about your english with me. You speak english far, FAR better than I speak [insert any other language here].
I admire anyone with multi-language skills. That is one area of serious weakness here in the U.S. We have never valued knowing
other languages, nearly enough. I had one semester of required Spanish in High School, and dropped it the instant I could.
Other countries require the study of other languages in grade school on. We could really learn a thing or two
from these other countries. Ah well. Maybe Google Translate will save my butt in time. But, right now, Google Translate works
fine with simple conversations, but if you take it into specialized fields, it's hopeless.

Anyway, thanks again! :good:
I will let you know if I get it to work.


That helps me a lot too mental!

I never quite understood how people managed plenty of tabs attached to the same code :O :good:
Now I have something to work out. nice!

edit: but wait..you have a directory opus on your desktop? amiga days!! :booze:


I couldn't go to bed without giving it a try.  =D

I managed to get the function SetRGB listed under 'sources', like you have in your picture, but when I right-click and choose "add file" it opens the function under a new tab, rather than appending it to my main code. Meh. I'm not sure it matters really. What it boils down to, even if it worked in the way you explained, is basically a cut-and-paste of the function to my main code rather than the call to an exterior function ability I was looking for. I guess I have my answer. Cut-and-paste it is.

Thanks Mentalthink!


HI Erico thanks, about this program on desktop, I downloaded yesterday, it's for change the explorer of windows, it's too much powerfull becuase you have ftp and  a lot of things, but I'm not sure if I continue whit this or I buy another more cheaper but more simply... It's something similar to total Commander, I think this it's the correct name...

CW, don't care if not it's this perhaps you can add whit a .ddl, you can compile a file like a .ddl and then add at this manner, but you can see the code inside... GLBasic have the Require command, but I'm not sure 100 if it's only for C++ and .mm files, then you can import external functions from Code do it in C++... but I think better it's make a wrapper... this it's in example did Gernnot whit 2D Physics and another C++ libs... only it's call whit native functions in GLbasic , external code... Take a look to 2DBox and you understand better I wnat say you...

Bye Bye  :-* :-*


No adding multiple soucefiles is way better than manually copy+paste code. Lets say you have your lib in a seperat folder and access it from there with multiple projects. If you change the lib now, the changes will have affect in all your projects without needing you to do anything else.

By the way there are two more ways with GLB: pack the lib into a gbal or compile it into a dll.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64


IIRC, while having multiple sourcefiles, only the one that changes needs recompiling when you press F5.
Could be useful speedwise on huge projects.
But I´m not fully sure.


Hey Kanonet,

After reading your post I went back and gave it another try, and it worked like a charm! An external function call, exactly like I wanted, without cutting or pasting.

MentalThink had it right, I just didn't go far enough. Right-clicking on "Sources" and choosing "New File" opened a file dialogue which allowed me to add my .gbas file ( which contained my SetRGB function) to the list, then right-clicking on that, and choosing "Add File" opened the function code under a new tab. That is where I stopped last night, because I thought I had failed. If I had only gone that extra step. lol

(Actually, now that I look closely at Mental's picture, his functions are on a separate tab, too, just as what I saw last night. I just didn't understand that this is exactly what was supposed to happen. Ah well.)

Just now I went back to my main program (By clicking on my "Test_External_Call" Main Program tab), and tried to use the function SetRGB(250). It lite up in that beautiful blue text, just as it would have done had I cut-and-pasted the the function over. But as you said; Now I can keep all of my personal functions in a dedicated folder, use them at will, and, should I ever need to update one of them, all of the programs which use that function from that location will be automatically up to date as well.

Color this issue solved. Thanks to my friends, MentalThink and Kanonet.   :good:

PS: Be careful with the "Delete File" option. It deletes the actual file from hard drive, not merely dismissing it from the project. You could potentially lose your personal library of functions that way. (If you don't practice good back-up habits, it could give you reason to wish you did.)  :blink:



But be aware: if you use one source file in two or more projects and open both projects at the same time, things can go horribly wrong! You may lose all the changes that you do to that lib.
So if you want to change a lib that is used in several projects, be sure that no other project that uses this lib is currently opened.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64


HI CW don't care I walys stay here to very late night, and sometimes cost test something...
Abbout my functions panel at left, this it's you can configure a bit the IDE, if you press in some determinated region in the funcions and the drag and drop to the left you will put in this post... equal if you put the console of the compiler...