Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Beginner Q] How to use subs/functions from external file?
#1
Hi all,

New user here, thanks for providing this forum & please bear with me...

I am trying to learn how to build my own external library of functions and/or subroutines.

Here is what I have right now:

Code: (Select All)
'$Include: 'mylib.bas'

AddNumbers

Error in message window: "Statement cannot be placed between SUB/FUNCTIONs on current line"

Code: (Select All)
' mylib.bas

' Add two numbers. Or don't.
Sub AddNumbers (a, b)
  'AddNumbersResult = a + b
  'Print "Adding: "; _ToStr$(a); " + "; _ToStr$(b); " = "; _ToStr$(AddNumbersResult)
  Print "Hello world."
End Sub

What I've tried so far:


  1. Adding, removing parens to/from the call to AddNumbers
  2. Adding, removing parameters to/from the call to AddNumbers - AddNumbers(2,3)
  3. Adding, removing "as Integer" to/from Sub/function parameters
  4. Using variables to call the sub/function, rather than literal integers
  5. Removing spaces between sub/function name and parens
  6. Converting the sub to function and back again
  7. Moving the include directive from top to bottom
  8. Adding a declaration of the sub to the library file
  9. Changing all function/sub logic to simply "Hello world." just in case
  10. Browsing the wiki entries for sub, function, include, etc.

The changes I made have changed the error message to say different things, but I haven't once been able to run the program after guessing which changes were required.

Any help is appreciated! Version I'm using is 4.0, Manjaro Linux. I am used to programming in other languages like PHP, Perl, Raku, Object Pascal, and others, but fairly new to this kind of library-call feature in basic dialects.
Reply


Messages In This Thread
[Beginner Q] How to use subs/functions from external file? - by sublogic - 02-02-2025, 09:23 PM



Users browsing this thread: 1 Guest(s)