1

如何调用在另一个 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

主程序

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

我将 main.bas 设置为主模块,但我不能调用 sum 函数....

4

2 回答 2

1

解决方案是在 main.bas 中编写 Declare 语句

sum.bas

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

主程序

Declare Function sum( As Integer, As Integer ) As Integer
Dim a As Integer
a = sum(1, 2)
Print a
Sleep
于 2021-07-31T17:31:39.373 回答
0

在 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

主程序

#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
于 2021-10-02T13:35:40.953 回答