Hello,
how do i call a function where it is declared in another bas file?
For example i have 2 bas files.
sum.bas
--------------------
Declare Function sum( As Integer, As Integer ) As Integer
Function sum( a As Integer, b As Integer ) As Integer
Return a + b
End Function
main.bas
---------------------
Dim a As Integer
a = sum(1, 2)
Print a
Sleep
I set main.bas as the main module but i cannot call sum function....
Call a Function from another bas file
-
- Posts: 237
- Joined: Jul 15, 2021 7:23
- Location: Greece
- Contact:
Re: Call a Function from another bas file
main.bas
sum.bas
Code: Select all
Declare Function sum( As Integer, As Integer ) As Integer
Dim a As Integer
a = sum(1, 2)
Print a
Sleep
Code: Select all
Function sum( a As Integer, b As Integer ) As Integer
Return a + b
End Function
-
- Posts: 237
- Joined: Jul 15, 2021 7:23
- Location: Greece
- Contact:
Re: Call a Function from another bas file
i did this and i get:
23:30:28: Compilation: "/home/user/Bin/FreeBASIC-1.08.1-ubuntu-20.04-x86_64/bin/fbc" -b "main.bas" -exx -i "/home/user/Bin/FreeBASIC-1.08.1-ubuntu-20.04-x86_64/include/freebasic" -p "/home/user/Bin/FreeBASIC-1.08.1-ubuntu-20.04-x86_64/lib/freebasic/linux-x86_64" 2> "/home/user/Bin/VisualFBEditor.1.2.9.1/Temp/Compile.log"
ld: main.o: in function `main':
main.c:(.text+0x7c): undefined reference to `SUM'
23:30:28: Do not build file.
i use Visual FB Editor 1.2.9
23:30:28: Compilation: "/home/user/Bin/FreeBASIC-1.08.1-ubuntu-20.04-x86_64/bin/fbc" -b "main.bas" -exx -i "/home/user/Bin/FreeBASIC-1.08.1-ubuntu-20.04-x86_64/include/freebasic" -p "/home/user/Bin/FreeBASIC-1.08.1-ubuntu-20.04-x86_64/lib/freebasic/linux-x86_64" 2> "/home/user/Bin/VisualFBEditor.1.2.9.1/Temp/Compile.log"
ld: main.o: in function `main':
main.c:(.text+0x7c): undefined reference to `SUM'
23:30:28: Do not build file.
i use Visual FB Editor 1.2.9
-
- Posts: 237
- Joined: Jul 15, 2021 7:23
- Location: Greece
- Contact:
Re: Call a Function from another bas file
i found it
the compiler does not compile sum.bas... it takes only main.bas...
it must be a bug on Visual FB Editor.
i run fbc main.bas sum.bas and it works
Thanks anyway
the compiler does not compile sum.bas... it takes only main.bas...
it must be a bug on Visual FB Editor.
i run fbc main.bas sum.bas and it works
Thanks anyway
Re: Call a Function from another bas file
Normally you would
#include "somefile.bas"
Does Visual FB Editor have a quick run or run only option?
If it does you could try this.
When you have tested uncomment the kill "sum.bas" to clean up.
#include "somefile.bas"
Does Visual FB Editor have a quick run or run only option?
If it does you could try this.
Code: Select all
dim as string s
s+="#define x 1"+chr(13,10)
s+="Function sum( a As Integer, b As Integer ) As Integer"+chr(13,10)
s+="Return a + b"+chr(13,10)
s+="End Function"+chr(13,10)
sub save(filename as string,s as string)
var f=freefile
open filename for output as #f
print #f,s
close
end sub
save("sum.bas",s)
'#include "sum.bas"
#ifdef x
Dim a As Integer
a = sum(1, 2)
Print "sum = ";a
#else
print "Run again, this time #include ""sum.bas"""
#endif
'kill "sum.bas"
sleep
-
- Posts: 789
- Joined: Jul 26, 2018 18:28
Re: Call a Function from another bas file
I added the ability to compile multiple files:
https://github.com/XusinboyBekchanov/Vi ... /issues/87
https://github.com/XusinboyBekchanov/Vi ... /issues/87