functioncallfreebasic

Call a Function from another bas file in FreeBASIC


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....


Solution

  • The solution is the Declare statement to be written in 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