在 FreeBASIC 中从另一个 bas 文件调用一个函数

Call a Function from another bas file in FreeBASIC

如何调用在另一个 bas 文件中声明的函数? 例如我有 2 个 bas 文件。

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

我将 main.bas 设置为主模块,但我无法调用求和函数....

解决方法是Declare语句写在main.bas

sum.bas

Function sum( a As Integer, b As Integer ) As Integer
Return a + b
End Function

main.bas

Declare Function sum( As Integer, As Integer ) As Integer
Dim a As Integer
a = sum(1, 2)
Print a
Sleep

像其他语言一样,在 FreeBASIC 中,可以将代码分成多个文件,其中主文件必须包含子文件,这些子文件使用#include "filename.bas"

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

#include "sum.bas"
'with "INCLUDE" it is as if the code contained in another file was written 
'at that point.

Dim a As Integer
a = sum(1, 2)
Print a
Sleep